public static void SaveData()
    {
        BinaryFormatter formatter = new BinaryFormatter();
        string          path      = Application.persistentDataPath + "/levelData.fun";
        FileStream      stream    = new FileStream(path, FileMode.Create);

        SaveAndExit data = new SaveAndExit();

        formatter.Serialize(stream, data);
        stream.Close();
    }
    public static SaveAndExit LoadData()
    {
        string path = Application.persistentDataPath + "/levelData.fun";

        if (File.Exists(path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(path, FileMode.Open);

            SaveAndExit data = formatter.Deserialize(stream) as SaveAndExit;
            stream.Close();

            return(data);
        }
        else
        {
            return(null);
        }
    }
Пример #3
0
    void OnEnable()
    {
        canContinue = SaveSystem.LoadData() != null;

        if (!canContinue)
        {
            continueButton.SetActive(false);
            textMesh.text = "";
        }
        else
        {
            SaveAndExit data = SaveSystem.LoadData();
            Debug.Log(data.currentSavedLevel + " --- " + data.savedDifficulty);
            GameManager.instance.currentLevel = data.currentSavedLevel;
            GameManager.instance.highestLevel = data.highestSavedLevel;
            GameManager.instance.attempts     = data.savedAttempts;
            GameManager.instance.difficulty   = (GameManager.Difficulties)data.savedDifficulty;
            textMesh.text = "Level: " + GameManager.instance.currentLevel + "\n" + "Difficulty: " + GameManager.instance.difficulty.ToString();

            continueButton.SetActive(true);
        }
    }