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.
- Listed in Items, inventory and logic
- Inherits or implements
NetworkEntityBehaviour - Documented in Other systems
Constructors
| Member | What it is |
|---|---|
NonPhysicalLever() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
20 private and internal fields
| Member | What it is |
|---|---|
private AltaEvent activated | Event fired when the lever enters the active angle. |
private Quaternion baseRotation | Rotation at the middle of the range. |
private Vector3 baseToHandle | Local direction from the pivot to the handle, cached in Awake. |
private AltaEvent deactivated | Event fired when the lever leaves the active angle. |
private Pickup handle | The pickup players grab. |
private float maxActive | Upper angle of the active band (default 50). |
private float maximumAngle | Angle at full (default 90). |
private float minActive | Lower angle of the active band (default 40). |
private float minimunAngle | Angle at empty. |
private Quaternion minRotation | Rotation at the minimum angle. |
private IUnityUpdateMethod moveTowards | Handle for the MoveTowards update. |
private int multiplier | 1 or -1, depending on whether the maximum angle is above the minimum. |
private Transform pivot | Transform rotated by the lever. |
private float range | Half the angle range, the most the pivot can turn from the middle. |
private Vector3 rotationAxis | Local axis the pivot turns around. |
private float syncMoveSpeed | Degrees per second when easing to a synced position (default 2). |
private MethodSync syncRelease | Method sync (SyncB) for the release position. |
private MethodSync syncSetup | Method sync (SyncA) for the position. |
private float target | Lever position from 0 to 1. |
private IUnityUpdateMethod trackMovement | Handle for the TrackMovement update. |
Properties
| Member | What it is |
|---|---|
bool IsActive { get; private set; } | True while the lever angle is between minActive and maxActive. |
1 private and internal property
Methods
11 private and internal methods
| Member | What 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. |