public T LoadJson <T>(string key, string fileName) where T : new () { ES3Settings _settings = new ES3Settings(); if (Isenscript) { _settings.encryptionType = ES3.EncryptionType.AES; _settings.encryptionPassword = secret; } if (fileName.IndexOf(".json") > -1) { fileName = fileName.Replace(".json", ""); } if (!ES3.FileExists(dirPath + "/" + fileName + ".json", _settings)) { Debug.LogWarning("没有" + dirPath + "/" + fileName); if (!ES3.RestoreBackup(dirPath + "/" + fileName + ".json", _settings)) { ES3.Save <T>(DataKey, new T(), dirPath + "/" + fileName + ".json", _settings); if (IsBackUp) { ES3.CreateBackup(dirPath + "/" + fileName + ".json", _settings); } } } string jsonpath = dirPath + "/" + fileName + ".json"; if (!ES3.KeyExists(key, jsonpath, _settings)) { throw new UnityException("没有" + key + "存在!"); } _settings.format = ES3.Format.JSON; try { return(ES3.Load <T>(key, jsonpath, _settings)); } catch { if (!ES3.RestoreBackup(jsonpath, _settings)) { ES3.Save <T>(DataKey, new T(), dirPath + "/" + fileName + ".json", _settings); if (IsBackUp) { ES3.CreateBackup(dirPath + "/" + fileName + ".json", _settings); } } throw new UnityException("no has " + dirPath + "/" + fileName + ".json"); } }
/// <summary> /// 玩家存档读取 /// </summary> /// <param name="_data"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> /// <exception cref="UnityException"></exception> public T LoadPlayerData <T>() where T : new() { ES3Settings _settings = new ES3Settings(); if (Isenscript) { _settings.encryptionType = ES3.EncryptionType.AES; _settings.encryptionPassword = secret; } if (!ES3.FileExists(dirPath + "/GameData.json", _settings)) { Debug.LogWarning("没有" + dirPath + "GameData.json!"); if (!ES3.RestoreBackup(dirPath + "/GameData.json", _settings)) { ES3.Save <T>(DataKey, new T(), dirPath + "/GameData.json", _settings); if (IsBackUp) { ES3.CreateBackup(dirPath + "/GameData.json", _settings); } } } T data = default(T); try { data = ES3.Load <T>(DataKey, dirPath + "/GameData.json", _settings); } catch { if (!ES3.RestoreBackup(dirPath + "/GameData.json", _settings)) { ES3.Save <T>(DataKey, new T(), dirPath + "/GameData.json", _settings); if (IsBackUp) { ES3.CreateBackup(dirPath + "/GameData.json", _settings); } } if (data == null) { if (Application.isEditor) { throw new UnityException("GameData.json 没有"); } Application.Quit(); } } return(data); }
public override void Enter() { backupWasRestored.Value = ES3.RestoreBackup(filePath.Value, GetSettings()); }
public void RestoreBackup() { ES3.RestoreBackup(file.settings); }