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.
- Listed in Items, inventory and logic
- Inherits or implements
NetworkEntityBehaviour,ISavableFull<LockableHingeSaveData>,ISavable<LockableHingeSaveData>,ISavableSave<LockableHingeSaveData>,ISavableSaveBase,ISavableFull - Derived types
Chest,LockableEvent,LockableHingeSaveData,LockableUnityEvent - Documented in Items, interaction and damage
Constructors
| Member | What it is |
|---|---|
LockableHinge() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
protected Lock currentLock | The lock fitted, or null. |
protected bool isLocked | Whether the lid is locked. |
protected HingeJoint lidJoint | The hinge joint whose limit changes when locked. |
protected Transform lockPosition | Where a detachable lock is attached. |
8 private and internal fields
| Member | What it is |
|---|---|
private ColliderGroup baseColliders | Colliders that ignore collisions with the attached lock's colliders. |
private LockableEvent isLockedEvent | Backing field for IsLockedEvent. |
private float lockedMaxAngle | Lid joint lower limit while locked (default -2 degrees). |
private uint lockHash | Prefab hash of a saved detached lock, set on load and used by LoadSetup to respawn it. |
private ConfigurableJoint lockJoint | Joint made by CreateLockJoint that holds a detached lock on; destroyed when the lock comes off. |
private float openMaxAngle | Lid joint lower limit while unlocked (default -150 degrees). |
private MethodSync syncLocked | Method sync (SyncA) that sends the locked flag. |
private MethodSync syncSetLock | Method sync (SyncB) that sends the locked flag and the attached lock; sent to each player on connect. |
Properties
| Member | What it is |
|---|---|
LockableEvent IsLockedEvent { get; } | Event raised when the locked state changes. |
Methods
| Member | What 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
| Member | What 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. |