Skip to main content

NonPhysicalLever

A class in Root.Township, Alta.Mechanisms.

A lever moved by hand without physics: the pivot rotates to follow the grip, fires events while inside an active angle, and syncs its final position on release.

Constructors​

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

Fields​

20 private and internal fields
MemberWhat it is
private AltaEvent activatedEvent fired when the lever enters the active angle.
private Quaternion baseRotationRotation at the middle of the range.
private Vector3 baseToHandleLocal direction from the pivot to the handle, cached in Awake.
private AltaEvent deactivatedEvent fired when the lever leaves the active angle.
private Pickup handleThe pickup players grab.
private float maxActiveUpper angle of the active band (default 50).
private float maximumAngleAngle at full (default 90).
private float minActiveLower angle of the active band (default 40).
private float minimunAngleAngle at empty.
private Quaternion minRotationRotation at the minimum angle.
private IUnityUpdateMethod moveTowardsHandle for the MoveTowards update.
private int multiplier1 or -1, depending on whether the maximum angle is above the minimum.
private Transform pivotTransform rotated by the lever.
private float rangeHalf the angle range, the most the pivot can turn from the middle.
private Vector3 rotationAxisLocal axis the pivot turns around.
private float syncMoveSpeedDegrees per second when easing to a synced position (default 2).
private MethodSync syncReleaseMethod sync (SyncB) for the release position.
private MethodSync syncSetupMethod sync (SyncA) for the position.
private float targetLever position from 0 to 1.
private IUnityUpdateMethod trackMovementHandle for the TrackMovement update.

Properties​

MemberWhat it is
bool IsActive { get; private set; }True while the lever angle is between minActive and maxActive.
1 private and internal property
MemberWhat it is
private Quaternion TargetRotation { get; }Pivot rotation for the current target between the angle limits.

Methods​

MemberWhat it is
void ForceEmpty(bool isEmpty)Moves the lever to 0 when true, or 1 when false.
void ForceFull(bool isFull)Moves the lever to 1 when true, or 0 when false.
override void Initialize()Makes the handle kinematic and creates the syncs.
void MoveToPosition(float lerp)Server: sets the lever's target (0 to 1), syncs it and eases the pivot there.
11 private and internal methods
MemberWhat it is
private void Awake()Caches the handle direction, hooks grab and release, and runs Setup.
private void MoveTowards()Each frame, rotates the pivot toward the target at syncMoveSpeed until it is there.
private void OnDestroy()Stops both update calls.
private void OnDrawGizmosSelected()Editor: draws the rotation axis.
private void OnValidate()Editor: reruns Setup.
private void Setup()Works out the middle rotation, half range, min rotation and direction from the angle limits.
private void StartTracking(Interactable interactable, Interactor interactor)On grab, starts following the hand and stops any easing.
private void StopTracking(Interactable interactable, Interactor interactor)On release, stops following once nobody holds it; the local player sends the final position.
private void SyncRelease(IPlayer player, Stream stream)Sends the release position; receivers ease to it, and the server passes it on to the other players.
private void SyncSetup(IPlayer player, Stream stream)Sends the position; receivers snap the pivot to it.
private void TrackMovement()Each frame while held, rotates the pivot toward the average grip point within range and fires activated or deactivated on change.