/// <summary> /// 加载 /// </summary> /// <returns>文件数据</returns> public override GlobalJson Load() { GlobalJson res; res.Values = new string[1]; bool error = false; GlobalJson json = LoadFile(fileName, LENGHT, () => { //异常... Debug.Log("GlobalFileLevels文件加载失败!!"); res = Default(); error = true; }); if (!error) { res = json; } int n1 = int.Parse(res.Values[0]); int n2 = int.Parse(res.Values[1]); int n3 = int.Parse(res.Values[2]); int n4 = int.Parse(res.Values[3]); int n5 = int.Parse(res.Values[4]); int n6 = int.Parse(res.Values[5]); int[] lvs = new int[6] { n1, n2, n3, n4, n5, n6 }; //GameData.SetLvs(lvs); return(res); }
/// <summary> /// 保存 /// </summary> /// <param name="json">文件数据</param> public override void Save(GlobalJson json) { GlobalJson saveJson; saveJson.Values = new string[json.Values.Length]; for (int i = 0; i < json.Values.Length; i++) { saveJson.Values[i] = json.Values[i]; } SaveFile(fileName, saveJson); }
protected void SaveFile(string fileName, GlobalJson json) { if (!Directory.Exists(rootPath)) { Directory.CreateDirectory(rootPath); } if (!System.IO.File.Exists(rootPath + fileName)) { FileStream fs = System.IO.File.Create(rootPath + fileName); fs.Close(); //关闭 fs.Dispose(); //释放 } StreamWriter sw = new StreamWriter(rootPath + fileName); string jsonString = JsonUtility.ToJson(json); sw.Write(jsonString); sw.Flush(); //刷新数据缓存 sw.Close(); sw.Dispose(); }
//实现抽象类 public abstract void Save(GlobalJson json);