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:
CombuManager.platform.LoadScores(123, 2, 10, (IScore[] scores) => {
Debug.Log("Scores loaded: " + scores.Length);
});
ILeaderboard 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) => {
});
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:
CombuManager.platform.ReportScore(1000, "123", (bool success) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed");
});
myScore.value = 1000;
myScore.ReportScore( (bool success) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed");
});
Loading Leaderboards data
To load the leaderboards data like the title, description etc, you need to call Leaderboard.Load:
Leaderboard.Load("123", (Leaderboard leaderboard, string error) => {
if (leaderboard != null)
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 LoadScoreByUser on a Leaderboard instance:
Leaderboard leaderboard = new Leaderboard { id = "123" };
leaderboard.LoadScoreByUser(CombuManager.localUser,
eLeaderboardInterval.Total, 10, (Score score,
int page,
string error) => {
if (score != null)
Debug.Log("Success: rank #" + score.rank + " with value " + score.value + " at page " + page);
else
Debug.Log("Failed: " + error);
});
eLeaderboardInterval
Leaderboard interval.
Definition: CombuEnums.cs:53