Unity关于easySave2 easySave3保存数据的操作;包含EasySave3运行报错的解决

这篇具有很好参考价值的文章主要介绍了Unity关于easySave2 easySave3保存数据的操作;包含EasySave3运行报错的解决。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

 关于easySave2 easySave3保存数据的操作;包含EasySave3运行报错的解决文章来源地址https://www.toymoban.com/news/detail-837198.html

 /// 数据存储路径(Easy Save的默认储存位置为:Application.persistentDataPath,为了方便我们可以给它指定储存路径) 

    #region 存储数据
    /*
    /// 
    /// 存储数据
    /// 
    private void SaveData()
    {


        ES2.Save(123, dataPath + "IntData");

        ES2.Save(1.23f, dataPath + "FloatData");

        ES2.Save(true, dataPath + "BoolData");

        ES2.Save("abc", dataPath + "StringData");

        ES2.Save(new Vector3(10, 20, 30), dataPath + "Vector3Data");

        ///< 存储transform 
        GameObject go = new GameObject();
        go.transform.localPosition = new Vector3(10, 20, 30);
        go.transform.localScale = new Vector3(3, 3, 3);
        ES2.Save(go.transform, dataPath + "TransformData");

        ///< 存储数组
        int[] intArray = new int[3] { 3, 2, 1 };
        ES2.Save(intArray, dataPath + "IntArrayData");

        ///< 存储集合
        List<string> stringList = new List<string>();
        stringList.Add("stringlist1");
        stringList.Add("stringlist2");
        stringList.Add("stringlist3");
        ES2.Save(stringList, dataPath + "StringListData");

        ///< 存储字典
        Dictionary<int, string> stringDict = new Dictionary<int, string>();
        stringDict.Add(1, "a");
        stringDict.Add(2, "b");
        ES2.Save(stringDict, dataPath + "StringDictData");

        ///< 存储栈
        Stack<string> stringStack = new Stack<string>();
        stringStack.Push("aaa");
        stringStack.Push("bbb");
        ES2.Save(stringStack, dataPath + "StringStackData");

        //保存图片 注意:该图片原文件属性“Advanced: Read/WriteEnable[*]”勾选可读写的
        // ES2.SaveImage(image.sprite.texture, "MyImage.png");
    }
    */
    #endregion


    #region 加载数据
    /*
    /// 
    /// 加载数据
    /// 
    private void LoadData()
    {
        int loadInt = ES2.Load<int>(dataPath + "IntData");
        Debug.Log("读取的int:" + loadInt);

        float loadFloat = ES2.Load<float>(dataPath + "FloatData");
        Debug.Log("读取的float:" + loadFloat);

        bool loadBool = ES2.Load<bool>(dataPath + "BoolData");
        Debug.Log("读取的bool:" + loadBool);

        string loadString = ES2.Load<string>(dataPath + "StringData");
        Debug.Log("读取的string:" + loadString);

        Vector3 loadVector3 = ES2.Load<Vector3>(dataPath + "Vector3Data");
        Debug.Log("读取的vector3:" + loadVector3);

        Transform loadTransform = ES2.Load<Transform>(dataPath + "TransformData");
        Debug.Log("读取的transform: Position++" + loadTransform.localPosition + " +++Scale++" + loadTransform.localScale);

        ///< 读取数组格式存储
        int[] loadIntArray = ES2.LoadArray<int>(dataPath + "IntArrayData");
        foreach (int i in loadIntArray)
        {
            Debug.Log("读取的数组:" + i);
        }

        ///< 读取集合格式存储
        List<string> loadStringList = ES2.LoadList<string>(dataPath + "StringListData");
        foreach (string s in loadStringList)
        {
            Debug.Log("读取的集合数据:" + s);
        }

        ///< 读取字典格式存储
        Dictionary<int, string> loadStringDict = ES2.LoadDictionary<int, string>(dataPath + "StringDictData");
        foreach (var item in loadStringDict)
        {
            Debug.Log("读取的字典数据: key" + item.Key + " value" + item.Value);
        }

        Stack<string> loadStringStack = ES2.LoadStack<string>(dataPath + "StringStackData");
        foreach (string ss in loadStringStack)
        {
            Debug.Log("读取的栈内数据:" + ss);
        }

        ///< 读取纹理 注意:该图片原文件属性“Advanced: Read/WriteEnable[*]”勾选可读写的
        Texture2D tex = ES2.LoadImage("MyImage.png");
        Sprite temp = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0, 0));
        //  showImage.sprite = temp;
    }
    */
    #endregion


    #region 删除数据
    /*
    /// 
    /// 删除数据
    /// 
    private void DeleteData()
    {
        ///< 判断是否有该存储key
        if (ES2.Exists(dataPath + "IntData"))
        {
            Debug.Log(ES2.Exists(dataPath + "IntData"));
            ///< 删除存储key
            ES2.Delete(dataPath + "IntData");
        }
    }
    */
    #endregion


    #region GUI测试用的 UI按钮
    /*
    void OnGUI()
    {
        if (GUI.Button(new Rect(0, 0, 100, 100), "储存数据"))
        {
            SaveData();
        }

        if (GUI.Button(new Rect(0, 100, 100, 100), "读取数据"))
        {
            LoadData();
        }

        if (GUI.Button(new Rect(0, 200, 100, 100), "删除数据"))
        {
            DeleteData();
        }
    }
    */

    #endregion


    #region  保存到本地/保存到web:

    /*


public IEnumerator UploadMesh(Mesh mesh, string tag)
{
    // Create a URL and add parameters to the end of it.
    string myURL = "http://www.server.com/ES2.php";
    myURL += "?webfilename=myFile.txt&webusername=user&webpassword=pass";

    // Create our ES2Web object.
    ES2Web web = new ES2Web(myURL + "&tag=" + tag);

    // Start uploading our data and wait for it to finish.
    yield return StartCoroutine(web.Upload(mesh));

    if (web.isError)
    {
        // Enter your own code to handle errors here.
        Debug.LogError(web.errorCode + ":" + web.error);
    }
}

public IEnumerator DownloadMesh(string tag)
{
    // Create a URL and add parameters to the end of it.
    string myURL = "http://www.server.com/ES2.php";
    myURL += "?webfilename=myFile.txt&webusername=user&webpassword=pass";

    // Create our ES2Web object.
    ES2Web web = new ES2Web(myURL + "&tag=" + tag);

    // Start downloading our data and wait for it to finish.
    yield return StartCoroutine(web.Download());

    if (web.isError)
    {
        // Enter your own code to handle errors here.
        Debug.LogError(web.errorCode + ":" + web.error);
    }
    else
    {
        // We could save our data to a local file and load from that.
        web.SaveToFile("myFile.txt");

        // Or we could just load directly from the ES2Web object.
        this.GetComponent<MeshFilter>().mesh = web.Load<Mesh>(tag);
    }
}


*/
    #endregion


    #region 最新版的easySave3运行会报错,按照以下修改即可:

    /*
     * 
    private void Start()
    {
        if (LoadEvent==LoadEvent.OnStart&&settings!=null)
        {
            Load();
        }
    }

    */
    #endregion


    #region 读取/保存 音频

    /*
    // Get the AudioSource we want to use to play our AudioClip.
    var source = this.GetComponent<AudioSource>();
    // Load an AudioClip from the streaming assets folder into our source.
    source.clip = ES3.LoadAudio(Application.streamingAssetsPath + "/AudioFile.wav");
    // Play the AudioClip we just loaded using our AudioSource.
    source.Play();

    // Get the AudioSource containing our AudioClip.
    var source = this.GetComponent<AudioSource>();
    // Save an AudioClip in Easy Save's uncompressed format.
    ES3.Save<AudioClip>("myAudio", source.clip);
    // Load the AudioClip back into the AudioSource and play it.
    source.clip = ES3.Load<AudioClip>("myAudio");
    source.Play();

        */
    #endregion


    #region 从Resource加载

    /*
    文件必须具有扩展名 例如:.bytes,以便能够从参考资料中加载它
     
    // Create an ES3Settings object to set the storage location to Resources.
    var settings = new ES3Settings();
    settings.location = ES3.Location.Resources;
 
    // Load from a file called "myFile.bytes" in Resources.
    var myValue = ES3.Load<Vector3>("myFile.bytes", settings);

    // Load from a file called "myFile.bytes" in a subfolder of Resources.
    var myValue = ES3.Load<Vector3>("myFolder/myFile.bytes");
    */

    #endregion


    #region 把 一堆键值数据 保存为string/byte[]
    /*
        // Create a new ES3File, providing a false parameter.
        var es3file = new ES3File(false);
 
        // Save your data to the ES3File.
        es3File.Save<Transform>("myTransform", this.transform);
        es3File.Save<string>("myName", myScript.name);
        // etc ...
 
        //保存为字符串
        string fileAsString = es3File.LoadRawString();
        //保存为 字节数组
        byte[] fileAsByteArray = es3File.LoadRawBytes().

    */
    #endregion

    #region 从 字符串/byte[] 读取

    /*
     * 
    //把字节数组转换成参数
    // If we're loading from a byte array, simply provide it as a parameter.
    var es3file = new ES3File(fileAsByteArray, false);

    // 把字符串转换为参数
    // 如果我们以字符串的形式加载,首先需要将其转换为字节数组,再把字节数组转换为参数。
    var es3file = new ES3File((new ES3Settings()).encoding.GetBytes(fileAsString), false);

    //再对应取出响应的值
    // Load the data from the ES3File.
    es3File.LoadInto<Transform>("myTransform", this.transform);//取出该值赋值到自身
    myScript.name = es3File.Load<string>("myName");   //取出 name
    // etc ...

     */

    #endregion


    #region  电子表格

    /*
        使用ES3Spreadsheet, Easy Save能够创建电子表格并以CSV格式存储,所有流行的电子表格软件都支持这种格式,包括      
       Excel、OSX数字和OpenOffice。

        保存:
        var sheet = new ES3Spreadsheet();
        // Add data to cells in the spreadsheet.
        for(int col=0; col<10; col++){
            for(int row=0; row<8; row++){
                sheet.SetCell<string>(col, row, "someData");
            }
        }
        sheet.Save("mySheet.csv");

    */

    /*
       如果要将数据追加到现有的电子表格,请将电子表格的追加变量设置为true。电子表格中的任何行都将被添加到保存到的行末尾。
       读取:
       // Create a blank ES3Spreadsheet.
        var sheet = new ES3Spreadsheet();
        sheet.Load("spreadsheet.csv");
        // Output the first row of the spreadsheet to console.
        for(int col=0; col<sheet.ColumnCount; col++)
            Debug.Log(sheet.GetCell<int>(col, 0));

       */

    #endregion

到了这里,关于Unity关于easySave2 easySave3保存数据的操作;包含EasySave3运行报错的解决的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Java操作elasticSearch复杂查询以及解析数据以及索引保存数据

    说明:基于银行测试库的操作 es的银行测试库,看一个Kibana操作 然后用java检索解析这个数据 聚合搜索 address 中包含 mill 的所有人的年龄分布以及平均薪资 以下是分解思路实现步骤: #聚合搜索 address 中包含 mill 的所有人的年龄分布以及平均年龄 GET bank/_search { “query”:{ “

    2024年02月10日
    浏览(50)
  • 【Unity 3D】C#从JSON文件中读取、解析、保存数据(附源码)

    JSON是一种轻量级的数据交换格式,采用完全独立于编程语言的文本格式存储和表示数据,简洁和清晰的层次结构使JSON成为理想的数据交换语言,易于读者阅读和编写,同时也易于机器解析和生成,并有效的提高网络传输效率 生成JSON数据实例代码如下 下面的代码将JSON中数据

    2024年02月11日
    浏览(45)
  • unity存储信息的方式,保存读取背包、游戏进度,连接MySQL数据库

    为了在Unity中存储信息,有几种方法可供选择。最常见的方法是 PlayerPrefs、Serialization和Database 。 PlayerPrefs是一种简单的存储小量数据(如玩家偏好或游戏设置)的方法。它易于使用,不需要任何外部库。但是,不建议用于存储大量数据或敏感信息。 Serialization是另一种在Unit

    2024年02月09日
    浏览(47)
  • STM32嵌入式系统:将数据保存到SD卡的操作

    STM32嵌入式系统:将数据保存到SD卡的操作 嵌入式系统在现代科技中扮演着重要角色,而STM32单片机是一种常用的嵌入式系统解决方案。本文将介绍如何使用STM32单片机将采集到的数据以TXT文件的格式保存到SD卡中,并且能够方便地读取这些本地数据。 硬件准备 为了实现数据保

    2024年02月01日
    浏览(33)
  • 3. QT环境下使用OPenCV操作图像数据(读取、保存、尺寸调节、色彩变换等)

    1. 说明 图像加载完成后,如果需要显示出来,需要使用 imshow 函数,在QT框架下,可以不使用这个函数。本文的操作都是将读取到的图像数据绘制到一个 QLabel 控件上即可。 使用opencv自带的显示函数示例:

    2024年02月09日
    浏览(34)
  • Unity用NPOI创建Exect表,保存数据,和修改删除数据。以及打包后的坑——无法打开新创建的Exect表

    先说坑花了一下午才找到解决方法解决, 在Unity编辑模式下点击物体创建对应的表,获取物体名字与在InputText填写的注释数据。然后保存。创建Exect表可以打开,打包PC后, 点击物体创建的表, 打不开文件破损 解决方法: 到unity编辑器所在路径中去找这个路径 EditorDataMon

    2024年02月12日
    浏览(43)
  • SQL Server基础 第三章 数据表基本操作(增删改查,不允许保存更改异常!)

    往表里插数据我们现在有两种方式 第一种是编辑直接修改,第二种是通过查询来修改数据 两种方法的区别 第一种更直接,如果数据量小那么直接改就好了,那如果数据量稍微庞大我们就需要用新建查询来进行表内容的修改了!!!!!!! 只需要新建查询,然后新的查询文

    2023年04月26日
    浏览(41)
  • spring boot 使用AOP+自定义注解+反射实现操作日志记录修改前数据和修改后对比数据,并保存至日志表

    使用FieldMeta自定义注解,看个人业务自行觉得是否需要重新定义实体 实现类 :通过该实现类获取更新前后的数据。 该实现类的实现原理为:获取入参出入的id值,获取sqlSessionFactory,通过sqlSessionFactory获取selectByPrimaryKey()该方法,执行该方法可获取id对应数据更新操作前后的数

    2024年01月23日
    浏览(41)
  • Redis关于Hash类型数据的操作,使用redisTemplate

    因为在redis的Hash数据类型里,有内层外层两个key,而且有内层外层两个map集合,所以暂时先称外层key为大key,内层key为小key,外层map为大map,内层map为小map,内层value值为value。 1.根据大key和小key还有value的值,设置一个value: 2.根据大key和小key获取到value值: 3.根据大key获取小

    2024年02月11日
    浏览(31)
  • 关于运用pycharm与数据库连接与实际操作

         数据库通常需要与编译软件相连接,本文主要介绍关于python 编译器pycharm与数据库连接的过程。 首先,pycharm需要一些基础的配置。 个人建议配置:终端---pip install pymysql        插件----DB Navigator 具体操作如下: 首先打开pycharm并新建项目  新建完成后,打开终端(右下

    2024年02月13日
    浏览(25)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包