Пример #1
0
    /// <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));
    }
Пример #2
0
    /// <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]);
        }
    }