Skip to main content

PlayerUnlockManager

A class in Root.Township, the global namespace.

A player's unlock progress for station chains such as the climbing tower: permanent unlocks, the run in progress, collected orbs and a checkpoint. One per player (player.UnlockManager); the server changes it, syncs it and saves it with the player.

Constructors​

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

Fields​

7 private and internal fields
MemberWhat it is
private IAnalyticsService analyticsServiceInjected analytics service used for unlock analytics.
private Vector3 checkpointBacking field for Checkpoint. Saved, not synced.
private PlayerUnlock currentUnlockBacking field for CurrentUnlock.
private static Logger loggerNLog logger for this class.
private HashSet<uint> orbsBacking field for Orbs.
private MethodSync syncMethod sync for SyncAll, sent on connect and whenever unlocks change.
private HashSet<PlayerUnlock> unlocksBacking field for Unlocks: the permanent unlocks, applied to the player when loading finishes.

Properties​

MemberWhat it is
Vector3 Checkpoint { get; }The run's checkpoint position. Saved but not synced to clients.
PlayerUnlock CurrentUnlock { get; }The unlock run in progress, or null.
HashSet<uint> Orbs { get; }Orb indexes collected in the current run.
HashSet<PlayerUnlock> Unlocks { get; }Unlocks the player has permanently.

Events​

MemberWhat it is
event Action ModifiedRaised whenever unlocks, the current run or orbs change.

Methods​

MemberWhat it is
void AddOrb(uint orbIndex)Server: adds a collected orb index and syncs. Indexes and count sync in 4 bits, so only 0 to 15 survive.
void CancelUnlock()Server: ends the current run and clears the checkpoint.
bool Check(PlayerUnlock unlock)Whether the player has an unlock permanently or is currently running it.
override void Initialize()Sets up the synced message and the orb light, and analytics for the local player.
void Inject(IAnalyticsService newAnalyticsService)Receives the analytics service through dependency injection.
override void OnConnected(Player player)Server: sends this player's unlock state to a new player.
void RemoveOrb(uint orb)Server: removes an orb index and syncs.
void SetCheckpoint(Vector3 newCheckpoint)Server: sets the checkpoint position.
void SetCurrentUnlock(PlayerUnlock unlock)Server: starts a run for an unlock if its prerequisites are met; null ends it and clears the checkpoint.
void SetPermanentUnlock(PlayerUnlock unlock, bool isUnlocked = true)Server: grants (if prerequisites are met) or removes an unlock, applying or removing its effects, and syncs.
protected override void PlayerLoadComplete()After the player loads, applies every permanent unlock to them and syncs.
8 private and internal methods
MemberWhat it is
private void NotifyPlayerUnlocksModified()Fires Modified.
private void OnDestroy()Unhooks the local-player-set handler.
private void SetupPlayerUnlockAnalytics(IPlayer localPlayer)Attaches unlock analytics when this manager belongs to the local player.
private void SyncAll(IPlayer player, Stream stream)Server to client: syncs orbs, the current unlock and the permanent unlocks, then fires Modified on clients.
private void SyncCurrentUnlock(IPlayer player, Stream stream)Syncs the current (in-progress) unlock, or that there is none.
private void SyncOrbs(IPlayer player, Stream stream)Syncs the set of orb indexes, 4 bits each, so at most 15 orbs.
private void SyncPermanentUnlocks(IPlayer player, Stream stream)Syncs the full set of permanent unlocks by hash.
private void SyncPlayerUnlocksToClient()Server: sends everything to chunks and fires Modified.

Used in​

Members of other types that take, return or hold a PlayerUnlockManager: