예제 #1
0
    public void SaveJson <T>(string key, T _data, string fileName)
    {
        if (_data == null)
        {
            throw new UnityException("存储对象为空!");
        }
        ES3Settings _settings = new ES3Settings();

        if (Isenscript)
        {
            _settings.encryptionType     = ES3.EncryptionType.AES;
            _settings.encryptionPassword = secret;
        }
        if (!Directory.Exists(dirPath))
        {
            Directory.CreateDirectory(dirPath);
        }
        if (fileName.IndexOf(".json") > -1)
        {
            fileName = fileName.Replace(".json", "");
        }
        string jsonpath = dirPath + "/" + fileName + ".json";

        _settings.format = ES3.Format.JSON;
        ES3.Save <T>(key, _data, jsonpath, _settings);
        if (IsBackUp)
        {
            ES3.CreateBackup(jsonpath, _settings);
        }
    }
예제 #2
0
 public void CreateBackup()
 {
     if (file == null)
     {
         return;
     }
     ES3.CreateBackup(file.settings);
 }
예제 #3
0
    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");
        }
    }
예제 #4
0
    /// <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);
    }
예제 #5
0
    string dirPath        = Application.persistentDataPath + "/Save"; //存档目录
    /// <summary>
    /// 玩家存档写入,自定义类型需要在assets/easysave3/openeasy3window/types添加
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public void SavePlayerData <T>(T _data)
    {
        ES3Settings _settings = new ES3Settings();

        if (Isenscript)
        {
            _settings.encryptionType     = ES3.EncryptionType.AES;
            _settings.encryptionPassword = secret;
        }
        if (!Directory.Exists(dirPath))
        {
            Directory.CreateDirectory(dirPath);
        }
        if (_data == null)
        {
            throw new UnityException("存储对象为空!");
        }
        ES3.Save <T>(DataKey, _data, dirPath + "/GameData.json", _settings);
        if (IsBackUp)
        {
            ES3.CreateBackup(dirPath + "/GameData.json", _settings);
        }
    }
예제 #6
0
 public override void Enter()
 {
     ES3.CreateBackup(filePath.Value, GetSettings());
 }