Skip to main content

Leaderboard

A class in Root.Township, the global namespace.

A leaderboard sign for a timed course. The server fills it from LeaderboardManager and syncs the top players, and each player's own best and latest times, to clients.

Constructors​

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

Fields​

14 private and internal fields
MemberWhat it is
private AltaEvent anyChangeEvent fired when any top row changes.
private LeaderboardDefinition definitionInspector-assigned course definition. Not read in this code, which uses definitionData.
private LeaderboardDefinitionData definitionDataThe course this board shows, loaded from the save or set by SetupDefinition.
private TransformHandler individualChangeEffect run on each top row that changes.
private TextRenderer latestText showing the player's most recent time.
private TextRenderer leaderboardNameText showing the course name.
private TextRenderer personalBestText showing the player's best time.
private TransformHandler personalBestChangeEffect run when the personal best text changes.
private MethodSyncStruct<Leaderboard.PersonalBest> syncPersonalBestSync message for SyncPersonalBest.
private MethodSyncStruct<bool> syncPlayersSync message for SyncPlayers.
private MethodSyncStruct<Leaderboard.PersonalBest> syncSetupSync message for SyncSetup.
private TextRenderer[] topPlayerNamesText rows for the top player names.
private List<PlayerData> topPlayersCurrent top players with their times.
private TextRenderer[] topPlayerTimesText rows for the top player times.

Methods​

MemberWhat it is
override void Initialize()Sets up the players, personal best and setup sync messages.
override async void InitializeAsServer(SpawnData spawnData)Server: loads and syncs the top players, and starts listening for time updates from the manager.
override void OnConnected(Player player)Server: sends a joining player's best time. It goes to the whole chunk, so every nearby client shows that time as its personal best.
async void SetupDefinition(LeaderboardDefinitionData updatedDefinition)Server: switches the board to a course definition, then loads and syncs its top players.
9 private and internal methods
MemberWhat it is
private async void CheckUpdate(LeaderboardDefinitionData updatedDefinition)Server: when the manager reports a new best for this board's course, reloads the top players and syncs them with effects.
private void OnDestroy()Stops listening to the manager's events.
private void SyncPersonalBest(IPlayer player, Stream stream, Leaderboard.PersonalBest arguments)Sends a player their new time. Remote clients show it as latest and, if it's a best, as personal best.
private void SyncPlayers(IPlayer player, Stream stream, bool hasEffect)Sends the top players and course name. Clients update the sign text.
private void SyncSetup(IPlayer player, Stream stream, Leaderboard.PersonalBest arguments)Sends a player's best time and the top players to clients that connect.
private void UpdateName(string courseName)Client: shows the course name on the sign.
private void UpdatePlayerBest(LeaderboardDefinitionData updatedDefinition, IPlayer player, int time, bool isBestTime)Server overload: forwards a time from the manager to that player. Client overload: updates the personal best and latest text.
private void UpdatePlayerBest(PlayerData data, bool isBestTime, bool isLatestTime = true)Server overload: forwards a time from the manager to that player. Client overload: updates the personal best and latest text.
private void UpdateText(bool hasEffect)Client: writes the top player names and times, firing change effects for rows that changed.