public T Load <T>() { T data = default(T); if (File.Exists(FilePath)) { FileStream stream = File.OpenRead(FilePath); try { BinaryFormatter bf = new BinaryFormatter(); var surrogateSelector = new SurrogateSelector(); Vector3Surrogate v3ss = new Vector3Surrogate(); surrogateSelector.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), v3ss); bf.SurrogateSelector = surrogateSelector; data = (T)bf.Deserialize(stream); } catch (Exception e) { Debug.LogException(e); } finally { stream.Close(); } } return(data); }
public void Save <T>(T data) { if (File.Exists(FilePath)) { File.Delete(FilePath); } using (FileStream stream = File.OpenWrite(FilePath)) { BinaryFormatter bf = new BinaryFormatter(); var surrogateSelector = new SurrogateSelector(); Vector3Surrogate v3ss = new Vector3Surrogate(); surrogateSelector.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), v3ss); bf.SurrogateSelector = surrogateSelector; bf.Serialize(stream, data); stream.Close(); } }