Skip to main content

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.

Constructors​

MemberWhat it is
TwoStepLever()Creates a TwoStepLever with default values.

Fields​

10 private and internal fields
MemberWhat it is
private float currentValueBacking field for Value.
private Pickup handleThe lever handle pickup.
private Transform handleTransformThe handle's transform, whose X angle is read.
private bool isHolderDrivenIf true, the holding player's client decides on or off and syncs it.
private float motionRangeMaxHandle X angle that counts as value 1. Defaults to -40.
private float motionRangeMinHandle X angle that counts as value 0. Defaults to -60.
private FloatEvent onValueChangedEvent fired with the new value when Value changes.
private MethodSync syncCurrentPositionMethod sync on SyncA for the handle position.
private MethodSync syncIsOnMethod sync on SyncB for the on/off state.
private float thresholdValue above which the lever is on. Defaults to 0.5.

Properties​

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

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