Пример #1
0
    void Save(SaveStuff dataToSave)
    {
        FileStream      file;
        BinaryFormatter binaryFormatter = new BinaryFormatter();

        file = File.Create(Application.persistentDataPath + savePath);

        binaryFormatter.Serialize(file, dataToSave);
        file.Close();
    }
Пример #2
0
 public static void Save()
 {
     BinaryFormatter bf = new BinaryFormatter();
     FileStream file = File.Create (Application.persistentDataPath + "/savedGames.gd");
     SaveStuff saveStuff = new SaveStuff ();
     saveStuff.Levels = GameBehaviour.Game.Levels;
     saveStuff.LevelUnlock = GameBehaviour.Game.LevelUnlock;
     saveStuff.Time = GameBehaviour.Game.Time;
     bf.Serialize(file, saveStuff);
     file.Close();
 }
Пример #3
0
    SaveStuff LoadData()
    {
        if (File.Exists(Application.persistentDataPath + savePath))
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            FileStream      file            = File.Open(Application.persistentDataPath + savePath, FileMode.Open);
            SaveStuff       data            = (SaveStuff)binaryFormatter.Deserialize(file);
            file.Close();

            return(data);
        }
        else
        {
            SaveStuff newData = new SaveStuff();                        //return  a new set of data if the file is not found
            return(newData);
        }
    }
Пример #4
0
    void GameOver()
    {
        bHasGameStarted = false;
        pauseMenuUI.SetActive(false);
        mainGameUI.SetActive(false);
        gameOverUI.SetActive(true);
        bShouldPauseGame = true;

        SaveStuff savedData = LoadData();

        savedData.AddDoCats(flyHits * doCatsPerFlyHit);

        switch (currentGameMode)
        {
        case GameModes.TIME30:
            if (goals > savedData.GetBest30sScore())
            {
                savedData.SetBest30sScore(goals);
            }
            highScoreText.text = savedData.GetBest30sScore().ToString();
            break;

        case GameModes.TIME60:
            if (goals > savedData.GetBest60sScore())
            {
                savedData.SetBest60sScore(goals);
            }
            highScoreText.text = savedData.GetBest60sScore().ToString();
            break;

        case GameModes.TIME90:
            if (goals > savedData.GetBest90sScore())
            {
                savedData.SetBest90sScore(goals);
            }
            highScoreText.text = savedData.GetBest90sScore().ToString();
            break;
        }
        Save(savedData);

        currentScoreText.text = goals.ToString();
        doCatsScore.text      = "$" + savedData.GetDoCats().ToString();
    }
Пример #5
0
    //public  Animator goalsTextAnimator;
    //public float shakeSpeed;

    void Start()
    {
        SaveStuff savedData = LoadData();

        bShouldPauseGame = false;
        mainGameUI.SetActive(true);
        pauseMenuUI.SetActive(false);
        gameOverUI.SetActive(false);

        currentGameMode = (GameModes)LoadGameMode();

        switch (currentGameMode)
        {
        case GameModes.TIME30:
            gameTime         = 10.0f;
            timeLeft         = 10.0f;
            currentHighScore = s30HighScore = savedData.GetBest30sScore();
            break;

        case GameModes.TIME60:
            gameTime         = 60.0f;
            timeLeft         = 60.0f;
            currentHighScore = s60HighScore = savedData.GetBest60sScore();
            break;

        case GameModes.TIME90:
            gameTime         = 90.0f;
            timeLeft         = 90.0f;
            currentHighScore = s90HighScore = savedData.GetBest90sScore();
            break;

        default:
            Debug.Log("ERROR: No game mode selected");
            timeLeft = 30.0f;
            break;
        }
        UpdateHUD();
        mainAudioSource = GetComponent <AudioSource>();
        //goalsTextAnimator = goalsText.GetComponent<Animator>();
    }