- Home /
GameCenterPlatform - Load leaderboards with custom parameters
Hello everyone :)
I'm implementing GameCenter using Unity's GameCenterPlatform.
I am aware of the default implementation using LoadScores, like the documentation suggests:
Social.LoadScores("Leaderboard01", scores => {
if (scores.Length > 0) {
Debug.Log ("Got " + scores.Length + " scores");
string myScores = "Leaderboard:\n";
foreach (IScore score in scores)
myScores += "\t" + score.userID + " " + score.formattedValue + " " + score.date + "\n";
Debug.Log (myScores);
}
else
Debug.Log ("No scores loaded");
});
The documentation states:
This uses default leaderboard parameters.
Unfortunately I am not aware what these "default parameters" are, I'm not sure what scores is returned from the leaderboard. Is there anyone who is aware of a way to retrieve scores based on your own custom search query?
Thank you for your time :)
Debug in Xcode says.... LoadScores retrieve only 10 scores from rank 1 to 10 using default parameters
Use m_$$anonymous$$erboard.range = new Range (m_$$anonymous$$erboard.localUserScore.rank, range);
Answer by abeldantas · Aug 18, 2017 at 08:50 PM
In Unity 5.6 you can do stuff like:
void ShowScoresForToday()
{
// OutputField is a Unity text element I'm using to debug this on the device
OutputField.text = "";
var leaderboardID = "leaderboard";
var log = string.Format( "Showing top score for leaderboard with id: '{0}'", leaderboardID );
Debug.Log( log );
OutputField.text = log;
var leaderboard = Social.CreateLeaderboard();
leaderboard.id = leaderboardID;
leaderboard.timeScope = TimeScope.Today;
leaderboard.LoadScores( success =>
{
var scores = leaderboard.scores;
if ( scores.Length > 0 )
{
foreach ( var score in scores )
{
var logLine = string.Format( "User with id '{0}' has a score of {1}, rank is {2}",
score.userID, score.value, score.rank );
OutputField.text += "\n" + logLine;
}
}
else
{
Debug.LogError( "No scores registered" );
}
} );
}
You have to initialize the Leaderboard object before querying, with the Social.CreateLeaderboard()
The filters are, hm, limited - https://docs.unity3d.com/ScriptReference/SocialPlatforms.ILeaderboard.html
Your answer
Follow this Question
Related Questions
Did Social.LoadUsers() stop working? 3 Answers
Social Api causing crashes 2 Answers
How can I show a specific leaderboard in iOS GameCenter? 2 Answers
Game Center login issue 0 Answers
When will Social.ReportScore() fail? 0 Answers