TwoStepLever
A class in Root.Township, the global namespace.
A lever with an on and off position: a Trigger whose state follows the handle's angle past a threshold. The handle position syncs to joining players.
- Listed in Global namespace: T to X
- Inherits or implements
Trigger,INetworkEntityBehaviour - Documented in Buttons and levers
Constructors
| Member | What it is |
|---|---|
TwoStepLever() | Creates a TwoStepLever with default values. |
Fields
10 private and internal fields
| Member | What it is |
|---|---|
private float currentValue | Backing field for Value. |
private Pickup handle | The lever handle pickup. |
private Transform handleTransform | The handle's transform, whose X angle is read. |
private bool isHolderDriven | If true, the holding player's client decides on or off and syncs it. |
private float motionRangeMax | Handle X angle that counts as value 1. Defaults to -40. |
private float motionRangeMin | Handle X angle that counts as value 0. Defaults to -60. |
private FloatEvent onValueChanged | Event fired with the new value when Value changes. |
private MethodSync syncCurrentPosition | Method sync on SyncA for the handle position. |
private MethodSync syncIsOn | Method sync on SyncB for the on/off state. |
private float threshold | Value above which the lever is on. Defaults to 0.5. |
Properties
| Member | What it is |
|---|---|
NetworkEntity Entity { get; private set; } | The network entity on this object. |
float Value { get; set; } | Handle position from 0 to 1. Setting a new value fires onValueChanged. |
Methods
| Member | What it is |
|---|---|
void ForceVisualSet(float value) | Moves the handle to a 0 to 1 position and sets the state from it, unless someone is holding it. |
12 private and internal methods
| Member | What it is |
|---|---|
private void Awake() | Caches the handle and entity, hooks the handle's grab and release events and reads the starting value. |
private void FixedUpdate() | While held, reads the handle angle and sets on or off. If holder driven, the holding client decides and syncs it. |
private void Alta.Networking.INetworkEntityBehaviour.Initialize() | Explicit INetworkEntityBehaviour method that creates the position and on/off method syncs. |
private void Alta.Networking.INetworkEntityBehaviour.InitializeAsServer(SpawnData spawnData) | Does nothing. |
private void InteractionEnded(Interactable interactable, Interactor interactor) | Stops the fixed update, reads the final value and makes the handle kinematic. |
private void InteractionStarted(Interactable interactable, Interactor interactor) | Turns on the fixed update while the handle is held. |
private void Alta.Networking.INetworkEntityBehaviour.OnConnected(Player player) | Sends the current handle position to a joining player. |
private void Alta.Networking.INetworkEntityBehaviour.OnDisconnected(Player player) | Does nothing. |
private void SetRotation(float rotation) | Sets the handle's X angle and updates Value to match. |
private void SyncCurrentPosition(IPlayer player, Stream stream) | Method sync for the handle position (0 to 1). Clients apply it with ForceVisualSet. |
private void SyncIsOn(IPlayer player, Stream stream) | Method sync for the on/off state. The server applies any sender's state and relays it without checks. |
private void UpdateValue() | Reads the handle's X angle and maps it to 0 to 1 between motionRangeMin and motionRangeMax. |
Used in
Members of other types that take, return or hold a TwoStepLever: