Beispiel #1
0
 public static T FromJsonWithZip <T>(byte[] content, bool zip = false)
 {
     if (zip)
     {
         var data = Zip7Helper.DecompressLZMA(content);
         return(JsonUtility.FromJson <T>(sUTF8NBOM.GetString(data)));
     }
     return(JsonUtility.FromJson <T>(sUTF8NBOM.GetString(content)));
 }
Beispiel #2
0
        public static T From <T>(string content, bool zip = false)
        {
            T ret = default(T);

            try {
                if (zip)
                {
                    var data = Zip7Helper.DecompressLZMA(sUTF8NBOM.GetBytes(content));
                    content = sUTF8NBOM.GetString(data);
                }
                ret = UnityEngine.JsonUtility.FromJson <T>(content);
            } catch (Exception exc) {
                UnityEngine.Debug.LogWarning(content + exc.Message);
            }
            return(ret);
        }
Beispiel #3
0
        public static string ToText <T>(T obj, bool zip = false, bool pretty = true)
        {
            string ret = string.Empty;

            try {
                ret = UnityEngine.JsonUtility.ToJson(obj, pretty);
                if (zip)
                {
                    var zipcontent = Zip7Helper.CompressLZMA(sUTF8NBOM.GetBytes(ret));
                    ret = sUTF8NBOM.GetString(zipcontent);
                }
            } catch (Exception exc) {
                UnityEngine.Debug.LogWarning(exc.Message);
            }
            return(ret);
        }
Beispiel #4
0
 public static T LoadJsonObject <T>(string path, bool zip = false)
 {
     try {
         if (zip)
         {
             var raw  = System.IO.File.ReadAllBytes(path);
             var data = Zip7Helper.DecompressLZMA(raw);
             return(JsonUtility.FromJson <T>(sUTF8NBOM.GetString(data)));
         }
         else
         {
             var content = System.IO.File.ReadAllText(path, sUTF8NBOM);
             return(JsonUtility.FromJson <T>(content));
         }
     } catch (Exception exc) {
     }
     return(default(T));
 }
Beispiel #5
0
 public static bool SaveJsonObject <T>(T obj, string path, bool zip = false)
 {
     try {
         string content = JsonUtility.ToJson(obj, true);
         if (zip)
         {
             var zipcontent = Zip7Helper.CompressLZMA(sUTF8NBOM.GetBytes(content));
             System.IO.File.WriteAllBytes(path, zipcontent);
         }
         else
         {
             System.IO.File.WriteAllText(path, content, new UTF8Encoding(false));
         }
     } catch (Exception exc) {
         return(false);
     }
     return(true);
 }