Пример #1
0
        public Registery(string startingScene)
        {
            snapshot = new RegisterySnapshot();
            snapshot.RefreshIdentifier();
            snapshot.lastScene = startingScene;

            objectData = new Dictionary<string, ObjectData>();
        }
Пример #2
0
        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();
        }
Пример #3
0
 public void LoadGameFromSnapshot(RegisterySnapshot snap)
 {
     Registery = LoadRegisteryFromFile(snap);
     Registery.snapshot.UpdateTime();
     SceneManager.LoadScene(snap.lastScene);
 }
Пример #4
0
 public void SaveRegistery(RegisterySnapshot snapshot)
 {
     snapshot.UpdateTimePlayed();
     WriteRegisteryToFile(snapshot);
 }
Пример #5
0
 private Registery CreateRegisteryFromSnapshot(RegisterySnapshot snap)
 {
     Registery registery = new Registery(startingScene);
     registery.snapshot = snap;
     return registery;
 }
Пример #6
0
        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);
            }
        }