public static T LoadLocalXML <T>(string key) where T : new() { object dataDeserialize = new T(); string content; string json; if (string.IsNullOrEmpty(LocalFilePath)) { return((T)dataDeserialize); } if (!File.Exists(LocalFilePath + key + localFileExtension)) { return((T)dataDeserialize); } // load from disc content = File.ReadAllText(LocalFilePath + key + localFileExtension); if (string.IsNullOrEmpty(content)) { return((T)dataDeserialize); } json = SGMd5Sum.Validate(content); if (string.IsNullOrEmpty(json)) { return((T)dataDeserialize); } dataDeserialize = JsonUtility.FromJson <T>(json); return((T)dataDeserialize); }
// ref: https://docs.unity3d.com/ScriptReference/Windows.File.WriteAllBytes.html public static bool SaveLocalXML(object dataSerializable, string key) { string json; if (string.IsNullOrEmpty(LocalFilePath)) { return(false); } json = JsonUtility.ToJson(dataSerializable, false); if (string.IsNullOrEmpty(json)) { return(false); } // save to disc File.WriteAllText(LocalFilePath + key + localFileExtension, SGMd5Sum.Sign(json)); return(true); }