// ----------------------------------------------------------------------------------- /// <summary> /// Load every ISaveable object registered with Add() /// </summary> /// <returns> true, if the file was loaded, false if it doesn't exist </returns> public bool Load(string filename) { if (!Exists(filename)) { return(false); } JSONObject json = EncryptedFile.ReadJSONObject(filename); foreach (KeyValuePair <string, ISaveable> kvp in _list) { if (json.HasField(kvp.Key)) { kvp.Value.OnLoad(json[kvp.Key]); } #if !RELEASE else { Debug.LogWarning("Found id " + kvp.Key + " in save file, but no object to load it"); } #endif } return(true); }
// ----------------------------------------------------------------------------------- /// <summary> /// Save every ISaveable object registered with Add() /// </summary> /// <param name="filename">Filename for the savefile</param> public void Save(string filename) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); foreach (KeyValuePair <string, ISaveable> kvp in _list) { json[kvp.Key] = kvp.Value.OnSave(); } EncryptedFile.WriteJSONObject(GetPath(filename), json); }