/// <summary> /// Does the actual load and returns raw object. /// </summary> /// <returns>The saved data.</returns> /// <param name="p">P.</param> protected static object LoadSavedData(Persistable p) { string data = PlayerPrefs.GetString(BasePlayerPrefId + p.Identifier, ""); if (data.Length > 0) { using (StringReader reader = new StringReader(data)){ XmlSerializer serializer = new XmlSerializer(p.SavedObjectType()); object savedObject = serializer.Deserialize(reader); return(savedObject); } } return(null); }
/// <summary> /// Load the given persistable. /// </summary> /// <param name="p">Persistable to laod.</param> public static void Load(Persistable p) { string data = PlayerPrefs.GetString(BasePlayerPrefId + p.Identifier, ""); if (data.Length > 0) { using (StringReader reader = new StringReader(data)){ XmlSerializer serializer = new XmlSerializer(p.SavedObjectType()); object savedObject = serializer.Deserialize(reader); p.ApplySaveData(savedObject); } } else { p.ResetSaveData(); } }