Skip to main content

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.

Constructors​

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

Fields​

24 private and internal fields
MemberWhat it is
private AnimationCurve angleCosToElevationCurve from lid angle (as a dot product) to dock elevation.
private AutomaticDockArea[] autoDocksAutomatic dock areas the server enables only while the lid is open.
private Pickup[] chestHandlesLid handle pickups whose grab can rattle a locked chest.
private NearbyPlayerScaler[] childDocksNearby-player scalers the client enables only while the lid is open.
private float closeDistanceHead distance within which the inner docks start to rise.
private LockableEvent creakEventBacking field for CreakEvent.
private PlayerCharacter currentPlayerThe local PlayerCharacter whose movement this chest is listening to.
private AnimationCurve distanceSqrdToElevationCurve from squared head distance to dock elevation.
private CurveElevation[] docksAnimationCurve elevations that move the inner docks up as the player leans in.
private bool isPlayerCloseTrue while the local player is within closeDistance, so LateUpdate keeps updating elevation.
private bool isPlayingEffectsSet by DelayEffects after 3 seconds; until then no lid sounds play.
private bool isRunningOnLateUpdateTrue when there is no PlayerCharacter to listen to, so distance is checked every frame.
private bool isSaveLoadingSkips the unlock pop force when true. Nothing in this class sets it.
private float jangleSensitivityDot product threshold of lid angle that counts as lifted, for the jangle and creak sounds.
private Vector3 jingleJangleTorqueTorque applied to the lock when it rattles.
private bool justJangledWhether the lid is currently past the jangle angle, so each crossing only plays once.
private bool lastStatusLast seen open state of the lid, used to detect opening and closing.
private Vector3 lidGizmoSizeSize of the editor gizmo box drawn on the lid.
private Rigidbody lidRigidbodyLid rigidbody that gets the pop force on unlock.
private Transform lidTransformCached transform of the lid joint.
private LockItemEvent lockJingleJangleBacking field for LockJingleJangle.
private Vector3 popForceImpulse applied to the lid at the lock position when the chest unlocks.
private LockableEvent thumpEventBacking field for ThumpEvent.
private Vector3 upThe chest's up direction cached in Awake, compared with the lid's to get its angle.

Properties​

MemberWhat 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​

MemberWhat it is
override void Initialize()Runs the base setup, then starts DelayEffects unless the build is headless.
override void SetLocked(bool isLocked)Locks or unlocks the lid; on unlock (outside save loading) also kicks the lid open with popForce.
10 private and internal methods
MemberWhat 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.