Exemple #1
0
 /// <summary>
 /// Save a data to local storage as JSON
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="val"></param>
 /// <param name="encryptKey"></param>
 /// <returns>Saved value</returns>
 public static string SaveAsJSON <T>(string dataName, T val, string encryptKey = null)
 {
     if (String.IsNullOrEmpty(encryptKey))
     {
         encryptKey = defaultEncryptKey;
     }
     if (encryptKey.Length != 16)
     {
         var ex = new Exception("encryptKey needs to be 16 characters!");
         Log.PrintError($"[JSaver] 错误:{ex.Message}, {ex.Data["StackTrace"]}");
         return(null);
     }
     try
     {
         string strData = StringifyHelper.JSONSerliaze(val);
         var    result  = CryptoHelper.EncryptStr(strData, encryptKey);
         PlayerPrefs.SetString(dataName, result);
         AddJSaverKeys(dataName);
         return(result);
     }
     catch (Exception ex)
     {
         Log.PrintError($"[JSaver] 错误:{ex.Message}, {ex.Data["StackTrace"]}");
         return(null);
     }
 }
Exemple #2
0
 /// <summary>
 /// Save a data to local storage as JSON
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="val"></param>
 /// <param name="encryptKey"></param>
 /// <returns>Saved value</returns>
 public static string SaveAsJSON <T>(string dataName, T val, string encryptKey = null)
 {
     if (String.IsNullOrEmpty(encryptKey))
     {
         encryptKey = Init.Instance.Key;
     }
     if (encryptKey.Length != 16)
     {
         var ex = new Exception("encryptKey needs to be 16 characters!");
         Log.PrintError(ex);
         return(null);
     }
     try
     {
         string strData = StringifyHelper.JSONSerliaze(val);
         var    result  = CryptoHelper.EncryptStr(strData, encryptKey);
         PlayerPrefs.SetString(dataName, result);
         return(result);
     }
     catch (Exception ex)
     {
         Log.PrintError(ex);
         return(null);
     }
 }