public Registery(string startingScene) { snapshot = new RegisterySnapshot(); snapshot.RefreshIdentifier(); snapshot.lastScene = startingScene; objectData = new Dictionary<string, ObjectData>(); }
private void WriteRegisteryToFile(RegisterySnapshot snapshot) { BinaryFormatter formatter = new BinaryFormatter(); FileStream snapFile = File.Create(Application.persistentDataPath + "/" + snapshot.identifier + ".gjs"); formatter.Serialize(snapFile, snapshot); snapFile.Close(); FileStream dataFile = File.Create(Application.persistentDataPath + "/" + snapshot.identifier + ".gjd"); formatter.Serialize(dataFile, Registery); dataFile.Close(); }
public void LoadGameFromSnapshot(RegisterySnapshot snap) { Registery = LoadRegisteryFromFile(snap); Registery.snapshot.UpdateTime(); SceneManager.LoadScene(snap.lastScene); }
public void SaveRegistery(RegisterySnapshot snapshot) { snapshot.UpdateTimePlayed(); WriteRegisteryToFile(snapshot); }
private Registery CreateRegisteryFromSnapshot(RegisterySnapshot snap) { Registery registery = new Registery(startingScene); registery.snapshot = snap; return registery; }
private Registery LoadRegisteryFromFile(RegisterySnapshot snapshot) { string path = Application.persistentDataPath + "/" + snapshot.identifier + ".gjd"; Registery registery = null; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream dataFile = File.Open(path, FileMode.Open); try { registery = (Registery)formatter.Deserialize(dataFile); return registery; } catch (Exception e) { Debug.Log(e.StackTrace); return CreateRegisteryFromSnapshot(snapshot); } finally { dataFile.Close(); } } else { return CreateRegisteryFromSnapshot(snapshot); } }