Unity Easy Save簡單實用


Easy Save使用:

   1.保存游戲進度
        2.設計游戲關卡(怪物數量,坐標,背景圖等等)
   

Easy Save默認存儲地址:

        C:\Users\Administrator\AppData\LocalLow\DefaultCompany\項目名
       

Easy Save保存的格式:(不能直接保存自定義類)

        http://moodkie.com/easysave/documentation/supported-types/ (保存的常見格式)
       

Unity路徑:

    Application.dataPath;                          //當前項目Asset路徑
        Application.streamingAssetsPath;        //當前項目Asset路徑\streamingAssets文件夾
        Application.persistentDataPath;            //持久化數據庫路徑
        Application.temporaryCachePath;          //臨時緩存路徑
       

簡單保存:

 

using UnityEngine;
using System.Collections;
using System.Collections.Generic;




public class EasySaveDemo1 : MonoBehaviour {

    public Student student;

    void OnGUI()
    {
        if (GUI.Button(new Rect(0, 0, 300, 120), "保存"))
        {
            Student student = new Student();
            student.name = "盤子";
            student.age = 18;
            student.height = 1.9f;
            student.marriage = false;

            List<Student> list = new List<Student>();


            //ES2Settings set = new ES2Settings(Application.dataPath + "myFile3.text");
            //set.encrypt = false;
            //set.encryptionPassword = "*";

            string path = Application.dataPath + "/關卡.text";

           //沒有保存起是不會拋異常的
              //多值保存到同一個文件
              ES2.Save(student.name, path + "?tag=name");
            ES2.Save(student.age, path + "?tag=age");
            ES2.Save(student.height, path + "?tag=height");
            ES2.Save(student.marriage, path + "?tag=marriage");
            

        }

        if (GUI.Button(new Rect(300, 0, 300, 120), "讀取"))
        {
            string path = Application.dataPath + "/關卡.text";
            student = new Student();
            student.name = ES2.Load<string>(path + "?tag=name");
            student.height = ES2.Load<float>(path + "?tag=height");
            student.age = ES2.Load<int>(path + "?tag=age");
            student.marriage = ES2.Load<bool>(path + "?tag=marriage");
            
        }

        if (this.student != null)
        {
            GUI.Label(new Rect(0, 120, 300, 120), "姓名:" + student.name);
            GUI.Label(new Rect(0, 150, 300, 120), "身高:" + student.height);
            GUI.Label(new Rect(0, 180, 300, 120), "年齡:" + student.age);
            GUI.Label(new Rect(0, 210, 300, 120), "婚姻:" + student.marriage);
        }


    }
    
}
public class Student 
{
    public string name;
    public int age;
    public float height;
    public bool marriage;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM