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))); }
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); }
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); }
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)); }
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); }