SelectionLever
A class in Root.Township, the global namespace.
A lever with a fixed number of positions between a min and max angle. Snaps to the nearest position on release and fires events. Not networked by itself.
- Listed in Global namespace: S
- Inherits or implements
MonoBehaviour - Attributes
ExecuteInEditMode - Documented in Buttons and levers
Constructors
| Member | What it is |
|---|---|
SelectionLever() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
21 private and internal fields
| Member | What it is |
|---|---|
private float angleOffset | Degrees added to the hand angle in GetLeverAngle. |
private IUnityUpdateMethod clampLever | Registered late update for ClampLever while the handle is held. |
private float currentAngle | Backing field for CurrentAngle. |
private int debugIndex | Position used by the editor debug button. |
private Transform gripPoint | Grip point of the hand holding the handle. Null when not held. |
private Pickup handle | Backing field for Handle. |
private Transform handleParent | Transform the handle goes back under when let go. |
private bool isResetVelocityOnRelease | Stops the handle's motion and makes it kinematic on release. True by default. |
private bool isSettingToDebugIndex | Editor button that runs SetDebugIndex. |
private bool isUsingCustomAngles | If set, selectionAngles is not recalculated in the editor. |
private Transform lever | Transform rotated to show the lever's angle. |
private float maxAngle | Backing field for MaxAngle. 160 by default. |
private float minAngle | Backing field for MinAngle. 15 by default. |
private BoolUnityEvent notZeroEvent | Unity event raised with whether the new selection is not 0. |
private int numberOfOptions | Backing field for NumberOfOptions. 2 by default. |
private float perIndex | Degrees between positions. |
private bool preventInteractionWhenOverZero | If set, the handle can't be grabbed while the selection is above 0 and is dropped when it moves there. |
private float radius | Distance from the lever to the handle, measured in Start. Not read after that. |
private bool runSelectionOnlyOnNotZero | If set, selectionEvent only fires for selections above 0. |
private float[] selectionAngles | Backing field for Selection: the angle of each position. |
private IntEvent selectionEvent | Unity event raised with the new selection index. |
Properties
| Member | What it is |
|---|---|
float CurrentAngle { get; } | The lever's angle while being held, clamped to the range. |
int CurrentSelection { get; private set; } | Index of the position the lever is set to. |
Pickup Handle { get; } | The Pickup the player grabs to move the lever. |
float MaxAngle { get; } | Angle of the last position. |
float MinAngle { get; } | Angle of the first position. |
int NumberOfOptions { get; } | How many positions the lever has. |
float[] Selection { get; } | The angle of each position. |
Events
| Member | What it is |
|---|---|
event Action<SelectionLever, int, int> SelectionChanged | Raised with the lever, old index and new index when the selection changes. |
Methods
| Member | What it is |
|---|---|
void SetLeverToIndex(int index) | Moves the lever to a position, clamped to the range, and fires the events if it changed. |
11 private and internal methods
| Member | What it is |
|---|---|
private void CalculatePerIndex() | Works out the angle between positions from the range and option count. |
private void ClampLever() | Late update while held: turns the lever to follow the hand, clamped to the range. |
private void FilterWhenActive(Interactor interactor, Interactable interactable, ref bool result) | Interaction filter that refuses grabs while the selection is above 0. Used with preventInteractionWhenOverZero. |
private float GetLeverAngle() | Angle of the gripping hand around the lever's X axis, plus angleOffset. |
private void LimitLever(Interactable arg1, Interactor arg2) | On grab, stores the hand's grip point and starts ClampLever each late update. |
private void OnValidate() | Editor: fills selectionAngles evenly across the range, unless custom angles are used. |
private void ResetVelocity() | Stops the handle's rigidbody and makes it kinematic. |
private void SelectOnRelease(Interactable arg1, Interactor arg2) | On release, snaps to the nearest position, resets the handle's velocity and puts it back on its parent. |
private void SetDebugIndex() | Editor button: moves the lever to debugIndex. |
private void SetLeverAngle(float angle) | Sets the lever's local X rotation. |
private void Start() | Measures the handle radius, works out the spacing and hooks the handle's grab, release and filter. |
Used in
Members of other types that take, return or hold a SelectionLever:
CustomScroller.lever, MenuToggleSetting.lever, MenuToggleSetting.ToggleSelection, ScrollerEnumMenuSetting.lever, ScrollerSelector.lever, StandardFloatAsEnum.lever, LeverToEvents.TriggerEvents, MultiLeverPanel.HandleSelection, MultiLeverPanel.levers, RuntimeConsole.lever, RuntimeConsole.OnLeverSelectionChanged, ServerSelectionMenu.boardLevers, SettingsPanel.HandleLeverChanged, SettingsPanel.SettingsPanelConfiguration.lever, SettingsPanel.SettingsPanelConfiguration.Lever, ThrottleCounter.selectionLever.