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.
- Listed in Global namespace: I to L
- Inherits or implements
NetworkEntityBehaviour,ISavable<LeaderboardData>,ISavableSave<LeaderboardData>,ISavableSaveBase - Derived types
LeaderboardData - Nested types
PersonalBest
Constructors
| Member | What it is |
|---|---|
Leaderboard() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
14 private and internal fields
| Member | What it is |
|---|---|
private AltaEvent anyChange | Event fired when any top row changes. |
private LeaderboardDefinition definition | Inspector-assigned course definition. Not read in this code, which uses definitionData. |
private LeaderboardDefinitionData definitionData | The course this board shows, loaded from the save or set by SetupDefinition. |
private TransformHandler individualChange | Effect run on each top row that changes. |
private TextRenderer latest | Text showing the player's most recent time. |
private TextRenderer leaderboardName | Text showing the course name. |
private TextRenderer personalBest | Text showing the player's best time. |
private TransformHandler personalBestChange | Effect run when the personal best text changes. |
private MethodSyncStruct<Leaderboard.PersonalBest> syncPersonalBest | Sync message for SyncPersonalBest. |
private MethodSyncStruct<bool> syncPlayers | Sync message for SyncPlayers. |
private MethodSyncStruct<Leaderboard.PersonalBest> syncSetup | Sync message for SyncSetup. |
private TextRenderer[] topPlayerNames | Text rows for the top player names. |
private List<PlayerData> topPlayers | Current top players with their times. |
private TextRenderer[] topPlayerTimes | Text rows for the top player times. |
Methods
| Member | What 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
| Member | What 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. |