public void OnBeforeSerialize() { var bf = new BinaryFormatter(UnitySerializationSurrogateSelector.GetSurrogateSelector(), new StreamingContext()); using (var ms = new MemoryStream()) { bf.Serialize(ms, things); bytes = ms.ToArray(); } }
public void OnAfterDeserialize() { if (bytes == null || bytes.Length == 0) { return; } var bf = new BinaryFormatter(UnitySerializationSurrogateSelector.GetSurrogateSelector(), new StreamingContext()); using (var ms = new MemoryStream(bytes)) { things = (Dictionary <string, object>)bf.Deserialize(ms); } }