Chest
A class in Root.Township, Alta.Inventory.
A lockable chest: a LockableHinge lid that pops open when unlocked, raises its inner docks as the local player leans in, and plays lid and lock sounds. Component on chest prefabs.
- Listed in Items, inventory and logic
- Inherits or implements
LockableHinge - Documented in Items, interaction and damage
Constructors
| Member | What it is |
|---|---|
Chest() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
24 private and internal fields
| Member | What it is |
|---|---|
private AnimationCurve angleCosToElevation | Curve from lid angle (as a dot product) to dock elevation. |
private AutomaticDockArea[] autoDocks | Automatic dock areas the server enables only while the lid is open. |
private Pickup[] chestHandles | Lid handle pickups whose grab can rattle a locked chest. |
private NearbyPlayerScaler[] childDocks | Nearby-player scalers the client enables only while the lid is open. |
private float closeDistance | Head distance within which the inner docks start to rise. |
private LockableEvent creakEvent | Backing field for CreakEvent. |
private PlayerCharacter currentPlayer | The local PlayerCharacter whose movement this chest is listening to. |
private AnimationCurve distanceSqrdToElevation | Curve from squared head distance to dock elevation. |
private CurveElevation[] docksAnimation | Curve elevations that move the inner docks up as the player leans in. |
private bool isPlayerClose | True while the local player is within closeDistance, so LateUpdate keeps updating elevation. |
private bool isPlayingEffects | Set by DelayEffects after 3 seconds; until then no lid sounds play. |
private bool isRunningOnLateUpdate | True when there is no PlayerCharacter to listen to, so distance is checked every frame. |
private bool isSaveLoading | Skips the unlock pop force when true. Nothing in this class sets it. |
private float jangleSensitivity | Dot product threshold of lid angle that counts as lifted, for the jangle and creak sounds. |
private Vector3 jingleJangleTorque | Torque applied to the lock when it rattles. |
private bool justJangled | Whether the lid is currently past the jangle angle, so each crossing only plays once. |
private bool lastStatus | Last seen open state of the lid, used to detect opening and closing. |
private Vector3 lidGizmoSize | Size of the editor gizmo box drawn on the lid. |
private Rigidbody lidRigidbody | Lid rigidbody that gets the pop force on unlock. |
private Transform lidTransform | Cached transform of the lid joint. |
private LockItemEvent lockJingleJangle | Backing field for LockJingleJangle. |
private Vector3 popForce | Impulse applied to the lid at the lock position when the chest unlocks. |
private LockableEvent thumpEvent | Backing field for ThumpEvent. |
private Vector3 up | The chest's up direction cached in Awake, compared with the lid's to get its angle. |
Properties
| Member | What it is |
|---|---|
LockableEvent CreakEvent { get; } | Event fired when an unlocked lid is lifted past the jangle angle. |
LockItemEvent LockJingleJangle { get; } | Event fired with the lock when someone tugs a locked chest's lid. |
LockableEvent ThumpEvent { get; } | Event fired when an unlocked lid falls back shut past the jangle angle. |
Methods
10 private and internal methods
| Member | What it is |
|---|---|
private void Awake() | Resets the dock animations, hooks the chest handles' grab event to HandleInteracted, and caches the lid transform. |
private IEnumerator DelayEffects() (iterator) | Coroutine started by Initialize on non-headless builds: waits 3 seconds, then turns on lid sound effects. |
private void HandleInteracted(Interactable handle, Interactor interactor) | Runs when a handle is grabbed: if the chest has a detached lock and is locked, rattles the lock and fires LockJingleJangle. |
private void JingleJangle() | Called each LateUpdate once effects are on: when the lid crosses the jangle angle, rattles the lock or fires CreakEvent/ThumpEvent. |
private void LateUpdate() | Updates dock elevation for a nearby player, turns child docks (client) and auto docks (server) on or off as the lid opens or closes, and runs JingleJangle. |
private void OnDisable() | Unhooks the local player events set up by OnEnable. |
private void OnDrawGizmosSelected() | Editor: draws a yellow box the size of lidGizmoSize on the lid. |
private void OnEnable() | Hooks PlayerController.LocalPlayerSet and sets the child and auto docks enabled to match whether the lid is open. |
private void SetLocalPlayer(PlayerController player) | Hooks the local player's movement to UpdateDistance, or falls back to checking every LateUpdate if the player is not a PlayerCharacter. |
private void UpdateDistance(PlayerController player, Vector3 oldPosition, Vector3 newPosition, LocomotionFunction function) | Client: raises the inner docks along their curves from the player's head distance and lid angle, or lowers them when the player is out of closeDistance. |