public void SaveHighscore(List <HighScoreData> listForHighScore) { ListHighScoreData list = new ListHighScoreData(); if (File.Exists("highscores.bin")) { var formatter = new BinaryFormatter(); FileStream stream = File.OpenRead("highscores.bin"); list = (ListHighScoreData)formatter.Deserialize(stream); stream.Close(); } foreach (HighScoreData data in listForHighScore) { list.list.Add(data); } File.Delete("highscores.bin"); FileStream stream2 = File.Create("highscores.bin"); var formatter2 = new BinaryFormatter(); formatter2.Serialize(stream2, list); stream2.Close(); }
public ListHighScoreData LoadHighscore() { ListHighScoreData list = new ListHighScoreData(); if (File.Exists("highscores.bin")) { var formatter = new BinaryFormatter(); FileStream stream = File.OpenRead("highscores.bin"); list = (ListHighScoreData)formatter.Deserialize(stream); stream.Close(); } return(list); }
// Start is called before the first frame update void Start() { list = sv.LoadHighscore(); }