示例#1
0
    public static void SaveHighScore()
    {
        // Construct Streams & Formatter to Start Saving
        BinaryFormatter formatter = new BinaryFormatter();
        FileStream      outStream = new FileStream(highScorePath, FileMode.Create);

        // Get the ONLY Data & Save it
        HighscoreData data = HighscoreData.getInstance();

        formatter.Serialize(outStream, data);
        outStream.Close();
    }
示例#2
0
    // Shows Game Over Canvas
    public void ShowGameOver(int score)
    {
        // Load in Highscore Data
        SaveSystem.LoadHighScore();

        // Get HighScore Data & Save
        HighscoreData hs    = HighscoreData.getInstance();
        bool          newHS = hs.setNewScore(score);

        SaveSystem.SaveHighScore();

        // Set the Score Texts
        CS_text.text = $"Score: {score}";
        HS_text.text = (newHS ? "NEW " : "") + $"Highscore: {hs.score}";

        // Start the Animation
        deathTransition.SetTrigger("Start");
    }
示例#3
0
    // Loads Data into Singleton Class
    // Returns True/False to indicate Loaded or not
    public static bool LoadHighScore()
    {
        // Verify File Exists
        if (File.Exists(highScorePath))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      inStream  = new FileStream(highScorePath, FileMode.Open);

            // Load in data
            HighscoreData data = formatter.Deserialize(inStream) as HighscoreData;

            // Save the Score
            HighscoreData.getInstance(data.score);
            inStream.Close();

            Debug.Log("Saved File to " + highScorePath);
            return(true);
        }
        else
        {
            Debug.LogError("Save file not found in " + highScorePath);
            return(false);
        }
    }