首先定义json的数据结构
public class Json_Data {
public int Id;
public string PlayerName;
public Skill_Data[] SkillList;
}
然后保存到一个列表里
public class Data
{
public List<Json_Data> datas = new List<Json_Data>();
}
拿到所有列表的静态对象 让他成为静态变量方便我们进入其他场景调用
public static class SaveData
{
public static Data AD;
public static Json_Data AM;
}
我这里文件暂时储存在了Resources里的 PlayerData里 但是在安卓和iOS只支持读怎么办呢,
下面我们就要在创建一个文件放到可读的路径 当那个可读路径没有文件时我们读Resources下的文件把他的内容复制下来,然后新建一个txt在我们的可读写路径下
public void Read()
{
#if UNITY_STANDALONE_WIN
TextAsset TA = Resources.Load("PlayerData") as TextAsset;
if (!TA)
{
return;
}
GoodsStr = TA.text;
#endif
#if UNITY_IOS
//判断文件是否存在