Enhance competitiveness by integrating leaderboards, allowing players to compare their scores and achievements.
Support
Use this to determine if you can implement leaderboards for your game on the current platform.
Check if the leaderboard feature is supported on the platform.
Bridge.leaderboard.isSupported
Check if built-in popup is supported.
Bridge.leaderboard.isNativePopupSupported
Check if multiple boards are supported.
Bridge.leaderboard.isMultipleBoardsSupported
Check if user can set score to leaderboard.
Bridge.leaderboard.isSetScoreSupported
Check if user can retrieve their score.
Bridge.leaderboard.isGetScoreSupported
Check if user can access leaderboard entries including other players' scores.
Bridge.leaderboard.isGetEntriesSupported
Player Scores. Set
Submit the player's score to the leaderboard to update their rank and position.
private void Start()
{
var options = new Dictionary<string, object>();
switch (Bridge.platform.id)
{
case "yandex":
options.Add("score", 42);
options.Add("leaderboardName", "YOUR_LEADERBOARD_NAME");
break;
case "facebook":
options.Add("score", 42);
options.Add("leaderboardName", "YOUR_LEADERBOARD_NAME");
break;
case "lagged":
options.Add("score", 42);
options.Add("boardId", "YOUR_LEADERBOARD_ID");
break;
case "y8":
options.Add("points", 42);
options.Add("table", "YOUR_LEADERBOARD_NAME");
break;
}
Bridge.leaderboard.SetScore(options, OnSetScoreCompleted);
}
private void OnSetScoreCompleted(bool success)
{
if (success)
{
// Operation succeeded
}
else
{
// An error occurred
}
}
Player Scores. Get
Retrieve the player's score from the leaderboard to display their current standing.
private void Start()
{
var options = new Dictionary<string, object>();
switch (Bridge.platform.id)
{
case "yandex":
options.Add("leaderboardName", "YOUR_LEADERBOARD_NAME");
break;
case "facebook":
options.Add("leaderboardName", "YOUR_LEADERBOARD_NAME");
break;
case "y8":
options.Add("table", "YOUR_LEADERBOARD_NAME");
break;
}
Bridge.leaderboard.GetScore(options, OnGetScoreCompleted);
}
private void OnGetScoreCompleted(bool success, int score)
{
if (success)
{
// Data successfully retrieved
Debug.Log(score);
}
else
{
// Something went wrong
}
}
Get Full Leaderboard
Retrieve entries from the leaderboard, including the player's rank and score, to display a comprehensive leaderboard.
Don't call SDK methods that require a callback (like Bridge.leaderboard.GetEntries
) when starting the game in Awake
. Call them in Start
.
private void Start()
{
var options = new Dictionary<string, object>();
switch (Bridge.platform.id)
{
case "yandex":
options.Add("leaderboardName", "YOUR_LEADERBOARD_NAME");
options.Add("includeUser", true);
options.Add("quantityAround", 10);
options.Add("quantityTop", 10);
break;
case "facebook":
options.Add("leaderboardName", "YOUR_LEADERBOARD_NAME");
options.Add("count", 10);
options.Add("offset", 10);
break;
case "y8":
options.Add("table", "YOUR_LEADERBOARD_NAME");
options.Add("page", 1);
options.Add("perPage", 10);
break;
}
Bridge.leaderboard.GetEntries(options, OnGetEntriesCompleted);
}
private void OnGetEntriesCompleted(bool success, List<Dictionary<string, string>> entries)
{
Debug.Log($"OnGetEntriesCompleted, success: {success}, entries:");
if (success)
{
switch (Bridge.platform.id)
{
case "yandex":
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"]);
}
break;
case "facebook":
foreach (var entry in entries)
{
Debug.Log("ID: " + entry["playerId"]);
Debug.Log("Score: " + entry["score"]);
Debug.Log("Rank: " + entry["rank"]);
Debug.Log("Name: " + entry["playerName"]);
Debug.Log("Photo: " + entry["playerPhoto"]);
}
break;
case "y8":
foreach (var entry in entries)
{
Debug.Log("ID: " + entry["playerid"]);
Debug.Log("Score: " + entry["points"]);
Debug.Log("Rank: " + entry["rank"]);
Debug.Log("Name: " + entry["playername"]);
}
break;
}
}
}
Shows leaderboard entries built-in popup
private void Start()
{
var options = new Dictionary<string, object>();
switch (Bridge.platform.id)
{
case "y8":
options.Add("table", "YOUR_LEADERBOARD_NAME");
break;
}
Bridge.leaderboard.ShowNativePopup(options, OnShowNativePopupCompleted);
}
private void OnShowNativePopupCompleted(bool success)
{
if (success)
{
// Data successfully retrieved
Debug.Log(score);
}
else
{
// Something went wrong
}
}