Exemplo n.º 1
0
    private void SaveScores()
    {
        ScoresWrapper scoresWrapper = new ScoresWrapper {
            scoresList = scores
        };
        string json = JsonUtility.ToJson(scoresWrapper);

        PlayerPrefs.SetString(PREFS_KEY, json);
        PlayerPrefs.Save();
    }
Exemplo n.º 2
0
    private List <Score> LoadScores()
    {
        // Attempt retrieving a LeaderBoard PlayerPref.
        string json = PlayerPrefs.GetString(key: PREFS_KEY, defaultValue: "");

        if (!json.Equals(""))
        {
            // If one is found, return the scoresList.
            ScoresWrapper scoresWrapper = JsonUtility.FromJson <ScoresWrapper>(json);
            return(scoresWrapper.scoresList);
        }

        // If one is not found, return a default scoresList.
        return(GenerateDefaultScores());
    }