unity数据的本地存储的方法
第一种方式:unity自带的存储方式PlayerPrefs
PlayerPrefs.SetString("login", "yes");
可以保存string int
第二种方式:通过JOSN或则XML文件保存本地数据
结构体或则类转JSON字符串
public class Student
{
public string name;
public int age;
}
string str = JsonUtility.ToJson(stu);
string FileUrl = Application.dataPath + "/JsonData.json";
File.WriteAllText(FileUrl, str);
读取JSON字符串 读取文件信息然后转成JSON
Student stu = new Student();
string FileUrl = Application.dataPath + "/JsonData.json";
string str= File.ReadAllText(FileUrl);
stu=JsonUtility.FromJson<Student>(str);
Debug.Log(stu.name + stu.age);