void Start() { DodiData data = SaveSystem.LoadData(); if (PlayerPrefs.GetString("activeGame").Equals("water")) { correctScore = data.currentQuestionsListPro.ElementAt(data.questionIndexPro).Value; } question.text = "Frage: " + data.currentQuestionsListPro.ElementAt(data.questionIndexPro).Key; answer.text = "Antwort: " + correctScore.ToString() + "%"; playerList = new Dictionary <string, float>(); differenceList = new Dictionary <string, float>(); for (int i = 1; i < 5; i++) { playerList.Add(PlayerPrefs.GetString(i.ToString()), PlayerPrefs.GetFloat(PlayerPrefs.GetString(i.ToString()))); differenceList.Add(playerList.ElementAt(i - 1).Key, Math.Abs(correctScore - playerList.ElementAt(i - 1).Value)); } var sortedList = from entry in differenceList orderby correctScore - entry.Value descending select entry; player1.text = "Platz 1: " + sortedList.ElementAt(0).Key + ": " + Math.Round(sortedList.ElementAt(0).Value, 2).ToString().Trim('[', ']') + "% unterschied"; player2.text = "Platz 2: " + sortedList.ElementAt(1).Key + ": " + Math.Round(sortedList.ElementAt(1).Value, 2).ToString().Trim('[', ']') + "% unterschied"; player3.text = "Platz 3: " + sortedList.ElementAt(2).Key + ": " + Math.Round(sortedList.ElementAt(2).Value, 2).ToString().Trim('[', ']') + "% unterschied"; player4.text = "Platz 4: " + sortedList.ElementAt(3).Key + ": " + Math.Round(sortedList.ElementAt(3).Value, 2).ToString().Trim('[', ']') + "% unterschied"; }
public static void saveDodiStats(FileManager manager) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/data.dodi"; FileStream stream = new FileStream(path, FileMode.Create); DodiData data = new DodiData(manager); formatter.Serialize(stream, data); stream.Close(); }
public static DodiData LoadData() { string path = Application.persistentDataPath + "/data.dodi"; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); DodiData data = formatter.Deserialize(stream) as DodiData; stream.Close(); return(data); } else { Debug.LogError("Dodi Data File not Found, " + path); return(null); } }