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.
- Listed in Global namespace: P
- Inherits or implements
PlayerComponent,ISavable<PlayerUnlockManagerSaveData>,ISavableSave<PlayerUnlockManagerSaveData>,ISavableSaveBase - Derived types
PlayerUnlockManagerSaveData - Documented in Skills and unlocks
Constructors
| Member | What it is |
|---|---|
PlayerUnlockManager() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
7 private and internal fields
| Member | What it is |
|---|---|
private IAnalyticsService analyticsService | Injected analytics service used for unlock analytics. |
private Vector3 checkpoint | Backing field for Checkpoint. Saved, not synced. |
private PlayerUnlock currentUnlock | Backing field for CurrentUnlock. |
private static Logger logger | NLog logger for this class. |
private HashSet<uint> orbs | Backing field for Orbs. |
private MethodSync sync | Method sync for SyncAll, sent on connect and whenever unlocks change. |
private HashSet<PlayerUnlock> unlocks | Backing field for Unlocks: the permanent unlocks, applied to the player when loading finishes. |
Properties
| Member | What 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
| Member | What it is |
|---|---|
event Action Modified | Raised whenever unlocks, the current run or orbs change. |
Methods
| Member | What 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
| Member | What 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: