Retrieving Leaderboard Data

You can still retrieve the data of a certain leaderboard and show it to the player. There are 3 ways to achieve this:

Global Top Scores

Retrieve a list of scores based on the best global scores:

[SerializeField]
SteamLeaderboards steamLeaderboards;

IEnumerator AsyncGetLeaderboardEntries()
{
    steamLeaderboards.GetCurrentLeaderboardGlobal(1, 10); // 1st to 10th plyers

    while(steamLeaderboards.IsGettingLeaderboardEntries)
    {
        yield return null; // Wait until leaderdords data are fetched
    }

    // Wait a while for the avatar images to load or ignore this line
    // if you only want to get the player names
    yield return new WaitForSeconds(1.5f);

    foreach (SteamLeaderboardEntry leaderboardEntry in steamLeaderboards.LeaderboardEntries)
    {
        // Do whatever you want
    }
}

Scores Around Player

Retrieve a list of scores around player:

[SerializeField]
SteamLeaderboards steamLeaderboards;

IEnumerator AsyncGetLeaderboardEntries()
{
    steamLeaderboards.GetCurrentLeaderboardGlobalAroundUser(-5, 5); // 5 before and 5 after player

    while(steamLeaderboards.IsGettingLeaderboardEntries)
    {
        yield return null; // Wait until leaderdords data are fetched
    }

    // Wait a while for the avatar images to load or ignore this line
    // if you only want to get the player names
    yield return new WaitForSeconds(1.5f);

    foreach (SteamLeaderboardEntry leaderboardEntry in steamLeaderboards.LeaderboardEntries)
    {
        // Do whatever you want
    }
}

Player And Friends

Retrieve the list of scores of the player and his friends

[SerializeField]
SteamLeaderboards steamLeaderboards;

IEnumerator AsyncGetLeaderboardEntries()
{
    steamLeaderboards.GetCurrentLeaderboardFriends();

    while(steamLeaderboards.IsGettingLeaderboardEntries)
    {
        yield return null; // Wait until leaderdords data are fetched
    }

    // Wait a while for the avatar images to load or ignore this line
    // if you only want to get the player names
    yield return new WaitForSeconds(1.5f);

    foreach (SteamLeaderboardEntry leaderboardEntry in steamLeaderboards.LeaderboardEntries)
    {
        // Do whatever you want
    }
}

The method AsyncGetLeaderboardEntries() is a Coroutine because calls to the Leaderboard API are asynchronous

Last updated