public static void Save(LevelMapData data) { string FilePath = XGamePath.GetLevelDataJsonPath(LevelMap_FileName); //string FilePath = Path.Combine(Application.dataPath, "FakeResources/Data/LevelConfig/" + data.Name + ".json"); LevelLoader.data = data; //Debug.Log("LevelMapData.Save==>" + FilePath); string json = JsonMapper.ToJson(data); string path = string.Format(FilePath, data.Name); try { if (File.Exists(path)) { File.Delete(path); } byte[] bytes = Encoding.UTF8.GetBytes(json); FileStream fs = File.Create(path); fs.Write(bytes, 0, bytes.Length); fs.Flush(); fs.Close(); } catch (Exception e) { Debug.Log(e + "==>" + e.Data); } }
public static void Save() { string path = XGamePath.GetLevelDataJsonPath(FileName); if (_ins == null) { _ins = new GameConfigData(); } string json = JsonMapper.ToJson(_ins); try { if (File.Exists(path)) { File.Delete(path); } byte[] bytes = System.Text.Encoding.UTF8.GetBytes(json); FileStream fs = File.Open(path, FileMode.CreateNew, FileAccess.Write); fs.Write(bytes, 0, bytes.Length); fs.Flush(); fs.Close(); Debuger.Log("GameConfig", "Save", string.Format("保存成功 路径={0},json={1}", path, json)); } catch (Exception e) { Debuger.Log("GameConfig", "Save", e + "==>" + e.Data); } }
public static LevelMapData Load() { if (data != null) { return(data); } string path = XGamePath.GetLevelDataJsonPath(LevelMap_FileName); //Debug.Log("LevelMapData.Load==>" + path); if (File.Exists(path)) { try { StreamReader fs = File.OpenText(path); string json = fs.ReadToEnd(); //ResMgr.Log(json); fs.Close(); data = JsonMapper.ToObject <LevelMapData>(json); return(data); } catch (Exception e) { Debug.Log(e + "==>" + e.Data); } } else { Debug.Log("file not exist"); } return(null); }
private static void Init() { string path = XGamePath.GetLevelDataJsonPath(FileName); if (File.Exists(path)) { try { StreamReader fs = File.OpenText(path); string json = fs.ReadToEnd(); fs.Close(); _ins = JsonMapper.ToObject <GameConfigData>(json); } catch (Exception e) { Debuger.Log("GameConfig", "load", e + "==>" + e.Data); } } else { Debuger.Log("GameConfig", "load", "file not exist"); } }