Skip to main content

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.

Constructors​

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

Fields​

27 private and internal fields
MemberWhat it is
private float currentAngleAngle the handle is shown at.
private float currentTargetAngle the handle is moving toward.
private float eventThresholdAngle past which the threshold events fire.
private Interactable handleThe Interactable players grab.
private bool isAligningHandleWithHandWhether the handle twists to match the hand.
private bool isLockedWhile true, the handle can only reach maxAngleLocked.
private bool isPivotStaticIf true, the pivot matrix is cached once instead of read every frame.
private bool isReturningWhenReleasedWhether the handle springs back to 0 when released.
private float maxAngleLockedLargest angle while locked.
private float maxAngleUnlockedLargest angle while unlocked.
private float minAngleSmallest angle.
private float movementLerpSpeedDegrees per second while dragged; -1 snaps.
private AnimationCurve movementToActualRotationCurve mapping the hand angle to the handle angle.
private IUnityUpdateMethod moveToHandHandle of the update method that follows the hand.
private Vector3 neutralAxisDirection, in pivot space, of angle 0.
private UnityEvent onPassedThresholdEvent fired when the angle goes above the threshold.
private BoolUnityEvent onThresholdChangedEvent fired with true or false when the angle crosses the threshold.
private Transform pivotTransform the hand position is measured against.
private float returnLerpSpeedDegrees per second when springing back; -1 snaps.
private IUnityUpdateMethod returnToDefaultHandle of the update method that springs back.
private Vector3 rotationAxisAxis the handle turns around.
private Transform rotationTargetTransform that is rotated.
private Matrix4x4 staticMatrixCached pivot world-to-local matrix when the pivot is static.
private MethodSync syncLockedMethod sync that sends the locked flag.
private Transform trackingInteractorGrip point of the hand being followed.
private static UpdateModule updateModuleShared late update module for all handles.
private bool wasAboveThresholdWhether the angle was above the threshold last update.

Methods​

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