示例#1
0
    /// <summary>
    /// Update the leaderboard text elements
    /// </summary>
    private void UpdateLeaderboardText()
    {
        //Early out if we have not text elements to write to
        if (leaderboardNames == null || leaderboardScores == null)
        {
            return;
        }

        //Get leaderboard info and the number of scores we need
        //to fill in
        var leaderboardInfo = ScoreLocalLeaderboards.GetSortedScores(SceneManager.GetActiveScene().name);
        int scoreCount      = Mathf.Min(leaderboardNames.Length, leaderboardScores.Length);

        //Update scores text
        for (int i = 0; i < scoreCount; i++)
        {
            //Check that we have scores, otherwise blank out
            if (i < leaderboardInfo.Count)
            {
                leaderboardNames[i].text = leaderboardInfo[i].Key;
                //Format the score using Standard numeric format strings -
                //https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings?redirectedfrom=MSDN#NFormatString
                leaderboardScores[i].text = scorePrefix + leaderboardInfo[i].Value.ToString("N0");
            }
            else
            {
                leaderboardNames[i].text  = string.Empty;
                leaderboardScores[i].text = string.Empty;
            }
        }
    }
    /// <summary>
    /// Add the current score to the leaderboard
    /// </summary>
    private void AddCurrentScoreToLeaderboard()
    {
        float  currentScore = ScoreKeeper.CurrentScore;
        string playerName   = GameOptionsManager.GetCurrentGameOptions().playerName;

        ScoreLocalLeaderboards.AddScore(playerName, currentScore, SceneManager.GetActiveScene().name);
    }
示例#3
0
    /// <summary>
    /// Update the leaderboard text elements
    /// </summary>
    private void UpdateLeaderboardText()
    {
        //Early out if we have not text elements to write to
        if (leaderboardNames == null || leaderboardScores == null)
        {
            return;
        }

        //Get leaderboard info and the number of scores we need
        //to fill in
        var leaderboardInfo = ScoreLocalLeaderboards.GetSortedScores(SceneManager.GetActiveScene().name);
        int scoreCount      = Mathf.Min(leaderboardNames.Length, leaderboardScores.Length);

        //Update scores text
        for (int i = 0; i < scoreCount; i++)
        {
            //Check that we have scores, otherwise blank out
            if (i < leaderboardInfo.Count)
            {
                leaderboardNames[i].text  = leaderboardInfo[i].Key;
                leaderboardScores[i].text = leaderboardInfo[i].Value.ToString();
            }
            else
            {
                leaderboardNames[i].text  = string.Empty;
                leaderboardScores[i].text = string.Empty;
            }
        }
    }
示例#4
0
    public static void DeleteLeaderboardFile()
    {
        string leaderboardFile = ScoreLocalLeaderboards.GetScoreSaveLocation(SceneManager.GetActiveScene().name);

        if (File.Exists(leaderboardFile))
        {
            File.Delete(leaderboardFile);
            Debug.Log("[Success] Reset all Leaderboard scores from file: " + leaderboardFile);
        }
        else
        {
            Debug.LogWarning("[Failed] Could not delete leaderboard file. Does not exist or is in use: " + leaderboardFile);
        }
    }