public bool Load() { try { if (File.Exists(Filepath)) { PersistentContainer obj; using (Stream stream = File.Open(Filepath, FileMode.Open, FileAccess.Read)) { BinaryFormatter bFormatter = new BinaryFormatter(); obj = (PersistentContainer)bFormatter.Deserialize(stream); } instance = obj; return(true); } else { using (Stream stream = File.Open(Filepath, FileMode.Create, FileAccess.ReadWrite)) { BinaryFormatter bFormatter = new BinaryFormatter(); bFormatter.Serialize(stream, this); } return(true); } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Exception in PersistentContainer.Load: {0}", e.Message)); } return(false); }
public static void Awake() { try { PersistentContainer.Load(); } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in StateManager.Awake: {0}", e)); } }
public static bool Load() { if (File.Exists(filepath)) { try { PersistentContainer obj; Stream stream = File.Open(filepath, FileMode.Open); BinaryFormatter bFormatter = new BinaryFormatter(); obj = (PersistentContainer)bFormatter.Deserialize(stream); stream.Close(); instance = obj; return(true); } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Exception in PersistentContainer.Load: {0}", e)); } } return(false); }
public static bool Load() { if (File.Exists(filepath)) { try { PersistentContainer obj; Stream stream = File.Open(filepath, FileMode.Open); BinaryFormatter bFormatter = new BinaryFormatter(); obj = (PersistentContainer)bFormatter.Deserialize(stream); stream.Close(); instance = obj; return true; } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Exception in PersistentContainer.Load: {0}", e)); } } return false; }