GameCenterPlatform - Load leaderboards with custom parameters

Hello everyone :slight_smile:

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:

";
foreach (IScore score in scores)
myScores += " " + score.userID + " " + score.formattedValue + " " + score.date + "
";
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 :slight_smile:

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 += "

" + 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 - Unity - Scripting API: ILeaderboard