Exemplo n.º 1
0
    public static int loadTimeTrialsCurrentBest(string difficulty)
    {
        try {
            FileStream      file = File.Open(Application.persistentDataPath + "/time_trials_" + difficulty + ".dat", FileMode.Open);
            BinaryFormatter bf   = new BinaryFormatter();

            TimeTrialsScore timeTrialsScore = (TimeTrialsScore)bf.Deserialize(file);
            currentBest = timeTrialsScore.best;
            file.Close();
        } catch {
            currentBest = 0;
        }
        return(currentBest);
    }
Exemplo n.º 2
0
    public static void saveTimeTrialsBest(int best, string difficulty)
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(
            Application.persistentDataPath + "/time_trials_" + difficulty + ".dat"
            );

        TimeTrialsScore timeTrialsScore = new TimeTrialsScore();

        timeTrialsScore.best = best;

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

        // Achievements & Leaderboards
        if (difficulty == "easy")
        {
            if (best >= 15)
            {
                Achievements.Easy15TimeTrials.Unlock();
            }
            Leaderboards.TimeTrialsEasyLeaderboard.SubmitScore(best);
        }
        else if (difficulty == "medium")
        {
            if (best >= 10)
            {
                Achievements.Medium10TimeTrials.Unlock();
            }
            Leaderboards.TimeTrialsMediumLeaderboard.SubmitScore(best);
        }
        else if (difficulty == "hard")
        {
            if (best >= 5)
            {
                Achievements.Hard5TimeTrials.Unlock();
            }
            Leaderboards.TimeTrialsHardLeaderboard.SubmitScore(best);
        }

        timeTrialsEasy   = loadTimeTrialsCurrentBest("easy");
        timeTrialsMedium = loadTimeTrialsCurrentBest("medium");
        timeTrialsHard   = loadTimeTrialsCurrentBest("hard");

        if ((timeTrialsEasy + timeTrialsMedium + timeTrialsHard) >= 30)
        {
            Achievements.TimeTrials30.Unlock();
        }
    }