• 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;
    }
  • 相关阅读:
    每日总结4.25
    每日总结4.24
    每日总结4.23
    每日博客4.22
    每日博客4.21
    每日博客4.20
    每日总结4.19
    每日总结4.16
    每日总结4.15
    每日总结4.14
  • 原文地址:https://www.cnblogs.com/zhepama/p/4360891.html
Copyright © 2020-2023  润新知