ThrottleCounter
A class in Root.Township, the global namespace.
Turns a spring-back SelectionLever into a stream of integer steps: the further the lever is pushed from its middle, the faster it counts. Runs where the player holds the lever.
- Listed in Global namespace: T to X
- Inherits or implements
MonoBehaviour
Constructors
| Member | What it is |
|---|---|
ThrottleCounter() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
14 private and internal fields
| Member | What it is |
|---|---|
private float buildupLerpSpeed | How fast the scroll speed ramps up towards the curve value. |
private IntEvent changedByInt | Backing event for ChangedByInt. |
private float currentValue | Running fractional count since the grab. |
private float deadRange | Fraction of the lever range near the middle that counts as no input. |
private int direction | Current count direction: 1 below the middle angle, -1 above, 0 at it. |
private float middleAngle | Lever's rest angle, from its first selection. |
private float negativeRange | Angle span from the middle down to the lever's minimum. |
private float positiveRange | Angle span from the middle up to the lever's maximum. |
private int roundedValue | Count rounded to an integer, used to work out each step change. |
private float scrollSpeed | Current count speed; resets when the direction flips. |
private SelectionLever selectionLever | The lever being read. |
private AnimationCurve speedCurve | Curve from lever push amount to count speed. |
private float speedMultiplier | Scales the count speed. |
private IUnityUpdateMethod update | Handle for the registered late update. |
Properties
| Member | What it is |
|---|---|
bool IsActive { get; set; } | If false, grabbing the lever does nothing. Default true. |
IPlayer LimitedToPlayer { get; set; } | If set, only this player's grab starts counting. |
Events
| Member | What it is |
|---|---|
event Action<int> ChangedByInt | Event with the change in whole steps each time the running count crosses an integer. |
Methods
4 private and internal methods
| Member | What it is |
|---|---|
private void Awake() | Reads the lever's middle and range angles and hooks its handle's grab and release. |
private void StartUpdating(Interactable interactable, Interactor interactor) | On grab, starts the late-update counting loop if active and the player is allowed. |
private void StopUpdating(Interactable interactable, Interactor interactor) | On release, stops counting and resets the count to zero. |
private void UpdateScroller() | Each frame, turns the lever angle into a speed, adds to the count and fires whole-step changes. |
Used in
Members of other types that take, return or hold a ThrottleCounter: