/// <summary> /// Ulozi tabulku na disk /// </summary> public void SaveToDisk() { if (save == null) { save = new SerializedScore().Init(); } save.Scores.Clear(); save.Players.Clear(); foreach (var kvp in this.scoreTable) { save.Players.Add(kvp.Key); save.Scores.Add(kvp.Value); } File.WriteAllText(saveFile, JsonUtility.ToJson(this.save)); }
/// <summary> /// Nacita tabulku z disku /// </summary> public void LoadFromDisk() { if (!File.Exists(saveFile)) { return; } string fileContent = File.ReadAllText(saveFile); save = JsonUtility.FromJson <SerializedScore>(fileContent); if (this.save.Players.Count != this.save.Scores.Count) { Debug.LogError("Player count not equal to score count"); return; } this.scoreTable.Clear(); for (int i = 0; i < save.Players.Count; i++) { this.scoreTable.Add(save.Players[i], save.Scores[i]); } }