码迷,mamicode.com
首页 > 编程语言 > 详细

Unity Easy Save简单实用

时间:2015-01-04 22:53:02      阅读:483      评论:0      收藏:0      [点我收藏+]

标签:

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;
}

Unity Easy Save简单实用

标签:

原文地址:http://www.cnblogs.com/plateFace/p/4202281.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!