Example #1
0
        public void LoadSavedGame()
        {
            if (File.Exists(Application.dataPath + SAVE_FILE))
            {
                BinaryFormatter bf       = new BinaryFormatter();
                FileStream      file     = File.Open(Application.dataPath + SAVE_FILE, FileMode.Open);
                GameData        gameData = (GameData)bf.Deserialize(file);

                scenes       = gameData.scenes;
                currentLevel = gameData.currentLevel;
                player       = gameData.player;
                file.Close();
            }
            else
            {
                scenes       = new Dictionary <string, SceneData>();
                currentLevel = SceneManager.GetActiveScene().name;
            }
        }
Example #2
0
        public void SaveGame()
        {
            if (File.Exists(Application.dataPath + SAVE_FILE))
            {
                LoadSavedGame();
            }
            else
            {
                File.Create(Application.dataPath + SAVE_FILE).Close();
                scenes = new Dictionary <string, SceneData>();
            }

            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.dataPath + SAVE_FILE, FileMode.Open);

            currentLevel         = SceneManager.GetActiveScene().name;
            scenes[currentLevel] = new SceneData();
            player = PlayerSerialization.GetSerialized();

            bf.Serialize(file, this);
            file.Close();
        }