Combu  2.1.14
Unity API Documentation
Managing Leaderboards

Table of Contents

In this section you will learn how to access the leaderboards data and report a score.

Loading Scores

To retrieve the scores list of a leaderboard you can call CombuManager.platform.LoadScores (by default loads the first page with 10 results), or you can instantiate a new Leaderboard object (created with CombuManager.platform.CreateLeaderboard), set timeScope, customTimescope and range and then call LoadScores:

// Load the scores of the leaderboard ID '123' from the page 2 with 10 results per page
CombuManager.platform.LoadScores(123, 2, 10, (IScore[] scores) => {
Debug.Log("Scores loaded: " + scores.Length);
});
// Load the scores of the leaderboard ID '123' from the page 1 with 10 results per page
Leaderboard board = CombuManager.platform.CreateLeaderboard();
board.id = "123";
board.timeScope = UnityEngine.SocialPlatforms.TimeScope.AllTime;
board.range = new UnityEngine.SocialPlatforms.Range(1, 10);
board.LoadScores((bool loaded) => {
// Now you can access board.scores and board.localUserScore
});

Reporting Scores

To report a new score of the local user you need to call CombuManager.platform.ReportScore, or you can call the method ReportScore on a Score instance:

// Report a score of 1000 to the leaderboard ID '123'
CombuManager.platform.ReportScore(1000, "123", (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});
// Report a score of 1000 on a Score object,
// (previously loaded with LoadScores or a new with leaderboardID set)
myScore.value = 1000;
myScore.ReportScore( (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});

Loading Leaderboards data

To load the leaderboards data like the title, description etc, you need to call Leaderboard.Load:

// Load the leaderboard ID '123'
Leaderboard.Load("123", (Leaderboard leaderboard, string error) => {
if (success)
Debug.Log("Success: " + leaderboard.title);
else
Debug.Log("Failed: " + error);
});

Loading the score of a user

To retrieve the best score of a user you need to call Leaderboard.LoadScoresByUser:

// Load the best score of leaderboard ID '123' for the User object with 10 results per page (to be attendible 'page', the limit must be the same as used with LoadScores)
Leaderboard.LoadScoresByUser("123", user, eLeaderboardInterval.Week, 10, (Score score, int page, string error) => {
if (success)
Debug.Log("Success: " + score.value + " at page " + page);
else
Debug.Log("Failed: " + error);
});