示例#1
0
        public void LoadGame()
        {
            if (File.Exists(Application.persistentDataPath + fileName))
            {
                using (FileStream file = File.Open(Application.persistentDataPath + fileName, FileMode.Open))
                {
                    BinaryFormatter fileFormat;
                    fileFormat = new BinaryFormatter();

                    GameSaveData saveData = (GameSaveData)fileFormat.Deserialize(file);
                    file.Close();

                    //LevelManager.Instance.SetLevelsStatus(saveData.levelsStatus);
                    //LevelManager.Instance.SetCurrentLevel(saveData.currentLevel);
                    CallLoadEvent();
                }
            }
        }
示例#2
0
        public void SaveGame()
        {
            //Windows Store Apps: Application.persistentDataPath points to %userprofile%\AppData\Local\Packages\<productname>\LocalState.
            //Mac : ~/Library/Application Support/company name/product name (Unity recent version)
            //Mac : ~/Library/Caches or ~/Library/Application Support/unity.company name.product name (Unity old version)
            using (FileStream file = File.Create(Application.persistentDataPath + fileName))
            {
                BinaryFormatter fileFormat;
                fileFormat = new BinaryFormatter();

                GameSaveData saveData = new GameSaveData();
                //saveData.levelsStatus = LevelManager.Instance.GetLevelsStatus();
                //saveData.currentLevel = LevelManager.Instance.GetCurrentLevel();

                fileFormat.Serialize(file, saveData);
                file.Close();
                CallSaveEvent();
            }
        }