PlayerWeight
A class in Root.Township, the global namespace.
Tracks how much a player is carrying: everything in their body docks plus what's in their hands. Server side; PlayerWeightStat listens to WeightChanged.
- Listed in Global namespace: P
- Inherits or implements
NetworkEntityBehaviour
Constructors
| Member | What it is |
|---|---|
PlayerWeight() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
3 private and internal fields
| Member | What it is |
|---|---|
private PickupDock[] docks | Backing field for Docks. |
private float? overridenWeight | Backing field for OverridenWeight. |
private PlayerController player | The player controller whose hands are checked. |
Properties
| Member | What it is |
|---|---|
IEnumerable<PickupDock> Docks { get; } | The player's body docks whose contents count toward the weight. |
float? OverridenWeight { get; set; } | When set, replaces the computed weight (spirit form sets it to the orbs' weight). Setting null goes back to the real total. |
float TotalWeight { get; private set; } | Current carried weight, or the override when one is set. |
Events
| Member | What it is |
|---|---|
event Action<PlayerController, float> WeightChanged | Raised with the player and new total whenever TotalWeight changes. |
Methods
| Member | What it is |
|---|---|
override void InitializeAsServer(SpawnData spawnData) | Server: hooks dock and hand events a frame later, and unhooks when the entity is destroyed. |
8 private and internal methods
| Member | What it is |
|---|---|
private float GetInteractablesWeight() | Weight of what the two hands hold, counting an item held in both hands once. |
private float GetInteractorsWeight(Interactor interactor) | Total weight of the pickup one hand holds, or 0. |
private void InteractionEnded(Interactor interactor, Interactable interactable) | When a hand lets go of a pickup, stops listening to its weight and recalculates. |
private void InteractionStarted(Interactor interactor, Interactable interactable) | When a hand grabs a pickup, listens to its weight changes and recalculates. |
private void OnWeightChanged() | Schedules a recalculation for the next frame. |
private void OnWeightChangedInternal() | Sums docks and hands into TotalWeight and raises WeightChanged if it changed. Skipped while OverridenWeight is set. |
private void SetupEvents() | Subscribes to dock weight changes and both hands' grab and release events, then calculates the first total. |
private void Unsubscribe(NetworkEntity entity, bool isUnload) | Stops listening to dock weight changes when the entity is destroyed. |
Used in
Members of other types that take, return or hold a PlayerWeight: