Skip to main content

LeaderboardManager

A class in Root.Township, the global namespace.

Server-side store of course times. Checkpoints report when a player starts and finishes a course, and it keeps each player's best and each board's top players. Get it through Instance.

Constructors​

MemberWhat it is
LeaderboardManager()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

2 private and internal fields
MemberWhat it is
private Dictionary<LeaderboardDefinitionData, List<LeaderboardManager.RankedPlayer>> availableLeaderboardsTop players for each course.
private Dictionary<int, LeaderboardManager.PlayerTracker> trackersRunning start times and best times for each player, by user ID.

Properties​

MemberWhat it is
static LeaderboardManager Instance { get; private set; }The manager in the scene.

Events​

MemberWhat it is
static event Action<LeaderboardDefinitionData> onBestTimeUpdatedRaised when a course's top list changes.
static event PlayerTimeUpdate onPlayerTimeUpdatedRaised when a player finishes a course, with the time and whether it's their best.

Methods​

MemberWhat it is
void Clear()Wipes all boards and player times. The best time events are meant to fire per board, but the key list is emptied first, so none fire.
static async Task GetPlayers(LeaderboardDefinitionData definition, List<PlayerData> players)Fills a list with a board's top players, looking up each username.
static int GetPlayersBestTime(LeaderboardDefinitionData definition, Player player)A player's best time on a course in seconds, or -1 if none.
static void MarkPlayer(IPlayer player, List<LeaderboardDefinitionData> beginnings, List<LeaderboardDefinitionData> endings)Server: starts timers for the courses a player begins and finishes timers for those they end, reporting each time. The private overload is empty.
override void OnDisconnected(Player player)Drops a leaving player's running course timers.
3 private and internal methods
MemberWhat it is
private void Awake()Sets Instance.
private static void MarkPlayer(IPlayer player, int time, LeaderboardDefinitionData ending)Server: starts timers for the courses a player begins and finishes timers for those they end, reporting each time. The private overload is empty.
private static void ValidateTopPlayers(LeaderboardManager.RankedPlayer rankedPlayer, LeaderboardDefinitionData leaderboardDefinition)Inserts a player into a board's top list in order. Nothing calls it, so finished runs never reach the top lists in this code.