Esempio n. 1
0
        public void Save()
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Create(Application.persistentDataPath + "/ProgressInfo.dat");

            LevelsData data = new LevelsData(levels.Length);

            for (int i = 0; i < levels.Length; i++)
            {
                data.levelStates[i] = levels[i].GetCurrentState();
            }

            bf.Serialize(file, data);
            file.Close();
        }
Esempio n. 2
0
        public void Load() // Loads player progress from file
        {
            if (File.Exists(Application.persistentDataPath + "/ProgressInfo.dat"))
            {
                BinaryFormatter bf   = new BinaryFormatter();
                FileStream      file = File.Open(Application.persistentDataPath + "/ProgressInfo.dat", FileMode.Open);
                LevelsData      data = new LevelsData(levels.Length);
                data = (LevelsData)bf.Deserialize(file);

                file.Close();

                for (int i = 0; i < data.levelStates.Length; i++)
                {
                    levels[i].SetState(data.levelStates[i]);
                }
                saveFileExists = true;
            }
            else
            {
                saveFileExists = false;
            }
        }
Esempio n. 3
0
        public void Reset()
        {
            // Reset all levels to locked state both in the save file and in the game
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Create(Application.persistentDataPath + "/ProgressInfo.dat");

            LevelsData data = new LevelsData(levels.Length);

            for (int i = 0; i < levels.Length; i++)
            {
                levels[i].SetState(Level.State.locked);

                data.levelStates[i] = Level.State.locked;
            }

            bf.Serialize(file, data);
            file.Close();

            // Unlock the first level and save the game
            firstLevel.SetState(Level.State.unlocked);
            Save();
        }