Leaderboards

Enhance competitiveness by integrating leaderboards, allowing players to compare their scores and achievements.

Leaderboards Type

Type of leaderboards on the current platform.

Bridge.leaderboards.type
Type
Game Logic

NotAvailable

Leaderboards are not available. Any leaderboard functionality must be disabled in the game.

InGame

Leaderboards are available.

The game must use the SetScore method to set the player's score.

The game should display custom in-game leaderboards using the data from the GetEntries method.

Native

Leaderboards are available.

The game must use the SetScore method to set the player's score.

The game should not display custom in-game leaderboards because leaderboards are displayed in the platform interface and the GetEntries method does not work.

Setup

Setup leaderboards in the config file. For each leaderboard add an id. You can override which id is sent to the platform's native SDK.

{
    ...    
    "leaderboards": [
        {
            "id": "test_leaderboard", // use this id in game logic
            "<ANY_PLATFORM_ID_HERE>": "<OVERRIDED_ID_FOR_PLATFORM_HERE>"
        }
    ]
}

Set Score

Submit the player's score to the leaderboard to update their rank and position.

private void Start()
{
    var leaderboardId = "YOUR_LEADERBOARD_ID"; // id that you specified in the config file
    var score = 42;
    Bridge.leaderboards.SetScore(leaderboardId, score, OnSetScoreCompleted);
}

private void OnSetScoreCompleted(bool success)
{
    if (success)
    {
        // Operation succeeded
    }
    else
    {
        // An error occurred
    }
}

Get Entries

Works only when Bridge.leaderboards.type = InGame

Retrieve entries from the leaderboard, including the player's rank and score, to display a custom leaderboard in the game.

private void Start()
{
    var leaderboardId = "YOUR_LEADERBOARD_ID"; // id that you specified in the config file
    Bridge.leaderboards.GetEntries(leaderboardId, OnGetEntriesCompleted);
}

private void OnGetEntriesCompleted(bool success, List<Dictionary<string, string>> entries)
{
    Debug.Log($"OnGetEntriesCompleted, success: {success}, entries:");
    
    if (success)
    {
        foreach (var entry in entries)
        {
            Debug.Log("ID: " + entry["id"]);
            Debug.Log("Score: " + entry["score"]);
            Debug.Log("Rank: " + entry["rank"]);
            Debug.Log("Name: " + entry["name"]);
            Debug.Log("Photo: " + entry["photo"]);
        }
    }
}

Last updated