/// <summary> /// Return all the Registery Snapshots stored under the saves directory /// </summary> /// <returns></returns> public static RegisterySnapshot[] LoadSnapshots() { BinaryFormatter serializer = new BinaryFormatter(); List <RegisterySnapshot> snaps = new List <RegisterySnapshot>(); string dirPath = Application.persistentDataPath + "/saves/"; if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } foreach (string file in Directory.GetFiles(Application.persistentDataPath + "/saves/")) { if (file.EndsWith(".gjs")) { FileStream stream = File.Open(file, FileMode.Open); RegisterySnapshot s = serializer.Deserialize(stream) as RegisterySnapshot; snaps.Add(s); stream.Close(); } } snaps.Sort(); snaps.Reverse(); return(snaps.ToArray()); }
public GameRegistery(string startlevel) { m_snapshot = new RegisterySnapshot(); m_snapshot.m_lastUpdate = DateTime.Now.ToBinary(); m_snapshot.m_currentScene = startlevel; NewID(); m_scenes = new Dictionary <string, SceneData>(); }
private static void LoadRegistery(RegisterySnapshot snap) { string path = "/saves/" + snap.m_identifier + ".gjd"; BinaryFormatter bf = new BinaryFormatter(); FileStream stream = File.Open(Application.persistentDataPath + path, FileMode.Open); Registery = bf.Deserialize(stream) as GameRegistery; stream.Close(); PausePlayTimer(false); GameController.TimeController.GameOver(false); BlockedSave = false; SceneManager.LoadScene(Registery.m_snapshot.m_currentScene); }
/// <summary> /// Load the regitery (and the party right after) /// Fire OnPreLoadEvent before any actions, then OnPostLoadEvent at the very end /// </summary> /// <param name="snap">The snapshot to load</param> public static void LoadGame(RegisterySnapshot snap) { if (OnPreLoadEvent != null) { OnPreLoadEvent(); } PausePlayTimer(true); LoadRegistery(snap); if (OnPostLoadEvent != null) { OnPostLoadEvent(); } }
/// <summary> /// Update and write the current Registery to disk. /// </summary> /// <param name="overriden">The snapshot file to override</param> public static void SaveAndWrite(RegisterySnapshot overriden) { Registery.m_snapshot.m_identifier = overriden.m_identifier; SaveAndWrite(false); }