using UnityEngine; using System.Collections; using System.Xml.Serialization; using System.IO; //DO NOT USE EXCEPT FOR DEBUGGING since it is slow //Based off http://entitycrisis.blogspot.com/2011/01/store-objects-in-playerprefs.html public class XMLPrefs { public static void Save(string name, T instance) { AVDebug.LogWarning("DO NOT USE EXCEPT FOR DEBUGGING since it is slow"); XmlSerializer serializer = new XmlSerializer(typeof(T)); using (var ms = new MemoryStream ()) { serializer.Serialize(ms, instance); PlayerPrefs.SetString(name, System.Text.ASCIIEncoding.ASCII.GetString(ms.ToArray())); } } public static T Load(string name) { AVDebug.LogWarning("DO NOT USE EXCEPT FOR DEBUGGING since it is slow"); if (!PlayerPrefs.HasKey(name)) { return default(T); } XmlSerializer serializer = new XmlSerializer(typeof(T)); T instance; using (var ms = new MemoryStream (System.Text.ASCIIEncoding.ASCII.GetBytes (PlayerPrefs.GetString (name)))) { instance = (T)serializer.Deserialize(ms); } return instance; } }