• Unity Easy Save简单实用


    Easy Save使用:

       1.保存游戏进度
            2.设计游戏关卡(怪物数量,坐标,背景图等等)
       

    Easy Save默认存储地址:

            C:UsersAdministratorAppDataLocalLowDefaultCompany项目名
           

    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;
    }
    如果你感兴趣,你可以把你妹妹介绍给我
  • 相关阅读:
    Dockershim 即将被移除?看 SUSE Rancher 的应对之道!
    使用 Rancher 进行首次金丝雀部署
    cOStoolkit:Container OS 的下一程
    如何在 K3s 中启用 Traefik Dashborad
    如何使用 Rancher Desktop 访问 Traefik Proxy 仪表板
    如何使用国内资源在 RKE2 上安装 Rancher HA
    Rancher 2.6 全新 Logging 快速入门
    实用教程 | 云原生安全平台 NeuVector 部署
    一文玩儿转 Rancher Desktop
    学多少年才算“精通Java”?
  • 原文地址:https://www.cnblogs.com/plateFace/p/4202281.html
Copyright © 2020-2023  润新知