LockedRotationHandle
A class in Root.Township, the global namespace.
Networked handle that turns around an axis as a player drags it, such as a lever or crank. It can be locked to a small angle, fires events past a threshold angle, and can spring back on release.
- Listed in Global namespace: I to L
- Inherits or implements
NetworkEntityBehaviour
Constructors
| Member | What it is |
|---|---|
LockedRotationHandle() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
27 private and internal fields
| Member | What it is |
|---|---|
private float currentAngle | Angle the handle is shown at. |
private float currentTarget | Angle the handle is moving toward. |
private float eventThreshold | Angle past which the threshold events fire. |
private Interactable handle | The Interactable players grab. |
private bool isAligningHandleWithHand | Whether the handle twists to match the hand. |
private bool isLocked | While true, the handle can only reach maxAngleLocked. |
private bool isPivotStatic | If true, the pivot matrix is cached once instead of read every frame. |
private bool isReturningWhenReleased | Whether the handle springs back to 0 when released. |
private float maxAngleLocked | Largest angle while locked. |
private float maxAngleUnlocked | Largest angle while unlocked. |
private float minAngle | Smallest angle. |
private float movementLerpSpeed | Degrees per second while dragged; -1 snaps. |
private AnimationCurve movementToActualRotation | Curve mapping the hand angle to the handle angle. |
private IUnityUpdateMethod moveToHand | Handle of the update method that follows the hand. |
private Vector3 neutralAxis | Direction, in pivot space, of angle 0. |
private UnityEvent onPassedThreshold | Event fired when the angle goes above the threshold. |
private BoolUnityEvent onThresholdChanged | Event fired with true or false when the angle crosses the threshold. |
private Transform pivot | Transform the hand position is measured against. |
private float returnLerpSpeed | Degrees per second when springing back; -1 snaps. |
private IUnityUpdateMethod returnToDefault | Handle of the update method that springs back. |
private Vector3 rotationAxis | Axis the handle turns around. |
private Transform rotationTarget | Transform that is rotated. |
private Matrix4x4 staticMatrix | Cached pivot world-to-local matrix when the pivot is static. |
private MethodSync syncLocked | Method sync that sends the locked flag. |
private Transform trackingInteractor | Grip point of the hand being followed. |
private static UpdateModule updateModule | Shared late update module for all handles. |
private bool wasAboveThreshold | Whether the angle was above the threshold last update. |
Methods
| Member | What it is |
|---|---|
override void Initialize() | Sets up the lock sync and grab events, and caches the pivot matrix if the pivot is static. |
override void OnConnected(Player player) | Server: sends the locked state to a joining player if locked. |
void UpdateLocked(bool isLocked) | Server: changes the locked state and syncs it to the chunks. |
12 private and internal methods
| Member | What it is |
|---|---|
private void AlignHandleWithHand() | If enabled, twists the handle so it lines up with the holding hand. |
private void BlockInteraction(Interactor interactor, Interactable interactable, ref bool result) | Interaction filter that refuses every grab; added while the handle springs back. |
private void EndTracking(Interactable interactable, Interactor interactor) | When the last player lets go, stops following the hand and, if set, starts returning to neutral. |
private void LerpToTarget() | Moves the current angle toward the target at the drag or return speed, or snaps if the speed is not positive. |
private void OnDestroy() | Removes the update methods. |
private void OnDrawGizmosSelected() | Empty. |
private void OnValidate() | Empty. |
private void ReturnToNeutral() | Update method that eases back to 0 and allows grabbing again once there. |
private void SetPosition() | Applies the current angle and fires the threshold events when it crosses eventThreshold. |
private void StartTracking(Interactable interactable, Interactor interactor) | On grab, cancels any spring back and starts following the hand's grip point. |
private void SyncLocked(IPlayer player, Stream stream) | Serializes the locked flag for the sync message. |
private void UpdatePosition() | Update method that works out the hand's angle around the axis, clamps it to the locked or unlocked range and moves toward it. |