Skip to main content

LockableHinge

A class in Root.Township, Alta.Inventory.

A hinged lid (chest and similar) that can be locked. A child Lock limits the hinge angle when locked; a detachable lock is attached at a lock point and saved with the lid.

Constructors​

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

Fields​

MemberWhat it is
protected Lock currentLockThe lock fitted, or null.
protected bool isLockedWhether the lid is locked.
protected HingeJoint lidJointThe hinge joint whose limit changes when locked.
protected Transform lockPositionWhere a detachable lock is attached.
8 private and internal fields
MemberWhat it is
private ColliderGroup baseCollidersColliders that ignore collisions with the attached lock's colliders.
private LockableEvent isLockedEventBacking field for IsLockedEvent.
private float lockedMaxAngleLid joint lower limit while locked (default -2 degrees).
private uint lockHashPrefab hash of a saved detached lock, set on load and used by LoadSetup to respawn it.
private ConfigurableJoint lockJointJoint made by CreateLockJoint that holds a detached lock on; destroyed when the lock comes off.
private float openMaxAngleLid joint lower limit while unlocked (default -150 degrees).
private MethodSync syncLockedMethod sync (SyncA) that sends the locked flag.
private MethodSync syncSetLockMethod sync (SyncB) that sends the locked flag and the attached lock; sent to each player on connect.

Properties​

MemberWhat it is
LockableEvent IsLockedEvent { get; }Event raised when the locked state changes.

Methods​

MemberWhat it is
override void Initialize()Creates the syncs.
override void InitializeAsServer(SpawnData spawnData)Server: fits and locks a child lock if one is found.
override void OnConnected(Player player)Sends the lock and locked state to a joining player.
virtual void SetLocked(bool isLocked)Locks or unlocks the lid and changes the hinge limit. Server: unlocking drops a detachable lock and syncs.
protected virtual void ApplyLock(Lock newLock)Fits a lock, or removes the old one. A built-in lock can't be removed. Server: syncs it.
7 private and internal methods
MemberWhat it is
private void CreateLockJoint(Rigidbody lockRigidbody)Adds a springy configurable joint holding a detached lock's rigidbody to the lid at lockPosition.
private void Alta.Chunks.ISavableFull.LoadSetup()Server, after loading: re-applies a saved detached lock, using a child lock if present or spawning one from the saved prefab hash.
private void LockTrigger(Lock eventLock)Server: listens to the current lock's locked event and copies its state with SetLocked.
private void OnValidate()Editor: picks up a child Lock as the current lock if none is set.
private void ResolveSaveLoadInEditor()Empty; called at the start of save and load.
private void SyncLocked(IPlayer player, Stream stream)Syncs the locked flag; clients apply it with SetLocked.
private void SyncSetLock(IPlayer player, Stream stream)Syncs the locked flag and which lock entity is attached; clients attach or detach that lock, waiting for it to spawn if needed.