Ejemplo n.º 1
0
        public Registery(string startingScene)
        {
            snapshot = new RegisterySnapshot();
            snapshot.RefreshIdentifier();
            snapshot.lastScene = startingScene;

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