Skip to main content

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.

Constructors​

MemberWhat it is
ThrottleCounter()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

14 private and internal fields
MemberWhat it is
private float buildupLerpSpeedHow fast the scroll speed ramps up towards the curve value.
private IntEvent changedByIntBacking event for ChangedByInt.
private float currentValueRunning fractional count since the grab.
private float deadRangeFraction of the lever range near the middle that counts as no input.
private int directionCurrent count direction: 1 below the middle angle, -1 above, 0 at it.
private float middleAngleLever's rest angle, from its first selection.
private float negativeRangeAngle span from the middle down to the lever's minimum.
private float positiveRangeAngle span from the middle up to the lever's maximum.
private int roundedValueCount rounded to an integer, used to work out each step change.
private float scrollSpeedCurrent count speed; resets when the direction flips.
private SelectionLever selectionLeverThe lever being read.
private AnimationCurve speedCurveCurve from lever push amount to count speed.
private float speedMultiplierScales the count speed.
private IUnityUpdateMethod updateHandle for the registered late update.

Properties​

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

MemberWhat it is
event Action<int> ChangedByIntEvent with the change in whole steps each time the running count crosses an integer.

Methods​

4 private and internal methods
MemberWhat 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: