The creator-centric platform for building live games in Unity

Easily add social, commerce, and content management features to your live game with low-code, drag-and-drop prefabs fully integrated with your Unity workflow.

Adding Leaderboard Interpolation

Allow player to manage a leaderboard with animated text

Overview

The purpose of this guide is for game makers to setup a LeaderboardLeaderboard - A list of high scores by all players of a game with interpolation.

Here, "interpolation" refers to a LeaderboardLeaderboard - A list of high scores by all players of a game with animated score text. The score value rises creating excitement in games with rapidly changing scores.

The User Interface

When setup properly, the player's user interface in the game project will be as follows.

Animated Screenshot

The Beamable "Leaderboard Flow" UI in the Unity Game WindowThe Beamable "Leaderboard Flow" UI in the Unity Game Window

The Beamable "Leaderboard Flow" UI in the Unity Game Window

Steps

Follow these steps to get started.

Step

Detail

  1. Setup a traditional "Leaderboard Flow" Prefab

• See Leaderboards » Prefab for more info

  1. Submit Leaderboard Score w/ Additional Stats

• See Send Score below

  1. Render Leaderboard Score w/ Additional Stats

• See Render Score below

Note: The provided example is built on top of the existing "Leaderboard Flow" Prefab. This has limited flexibility. Depending on the needs of the project, game makers may choose instead to build a custom Leaderboard UI from scratch. In either case the provided example serves as a useful model

Example

Here are examples which cover common programming needs.

📘

Beamable SDK Examples

This and all examples are available for download at GitHub.com/Beamable_SDK_Examples

Code

Submit Score

Here is a snippet from LeaderboardFlowInterpolationExample.cs;

public async void SendScore (IBeamableAPI beamableAPI, LeaderboardContent leaderboardContent, long score)
{
   Dictionary<string, object> leaderboardStats = new Dictionary<string, object>();
   leaderboardStats.Add("leaderboard_score_timestamp", new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds());
   leaderboardStats.Add("leaderboard_score_velocity", 99); // 99 score delta per second
   await beamableAPI.LeaderboardService.SetScore(leaderboardContent.Id, score, leaderboardStats);
}

Render Score

Here is a snippet from LeaderboardItemCustom.cs;

public void Update()
{
    // Prepare value
    long scoreTimestamp = long.Parse(_rankEntry.GetStat("leaderboard_score_timestamp"));
    long scoreVelocity = long.Parse(_rankEntry.GetStat("leaderboard_score_velocity"));
    long currentTimestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
    long millisecondsSinceSubmission = currentTimestamp - scoreTimestamp;
    long scoreSinceSubmission = (millisecondsSinceSubmission * scoreVelocity) / 1000;
   
    // Render value
    double score = _rankEntry.score + scoreSinceSubmission;
    TxtScore.text = $"{score:00000}";
}

Advanced

This section contains any advanced configuration options and workflows.

Updated 11 days ago


Adding Leaderboard Interpolation


Allow player to manage a leaderboard with animated text

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.