public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) { StorageSaveData data = (StorageSaveData)obj; data.storageItems = new List <StorageCharacterItem>(info.GetListValue <StorageCharacterItem>("storageItems")); obj = data; return(obj); }
public void LoadPersistentData(string id) { string path = Application.persistentDataPath + "/" + id + "_storage.sav"; storageItems.Clear(); if (File.Exists(path)) { BinaryFormatter binaryFormatter = new BinaryFormatter(); SurrogateSelector surrogateSelector = new SurrogateSelector(); surrogateSelector.AddAllUnitySurrogate(); StorageCharacterItemSerializationSurrogate storageCharacterItemSS = new StorageCharacterItemSerializationSurrogate(); StorageSaveDataSerializationSurrogate storageSaveDataSS = new StorageSaveDataSerializationSurrogate(); surrogateSelector.AddSurrogate(typeof(StorageCharacterItem), new StreamingContext(StreamingContextStates.All), storageCharacterItemSS); surrogateSelector.AddSurrogate(typeof(StorageSaveData), new StreamingContext(StreamingContextStates.All), storageSaveDataSS); binaryFormatter.SurrogateSelector = surrogateSelector; FileStream file = File.Open(path, FileMode.Open); StorageSaveData result = (StorageSaveData)binaryFormatter.Deserialize(file); storageItems = result.storageItems; file.Close(); } }
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context) { StorageSaveData data = (StorageSaveData)obj; info.AddListValue("storageItems", data.storageItems); }