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(); }
// 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"); }
// 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); } }