Skip to main content

CustomScroller

A class in Root.Township, Alta.Menu.

A rotating drum menu driven by a SelectionLever: holding the lever off-centre spins the drum and steps through a list of string values. Used by the server creator.

Constructors​

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

Fields​

20 private and internal fields
MemberWhat it is
private float anglePerSideDegrees of drum rotation per side (360 divided by numberOfSides).
private float currentAngleCurrent drum rotation in degrees.
private int currentlySelectedPanelWhich physical drum side is facing the player.
private float debugLeverAngleLever angle used instead of the real one when isUsingDebugLeverAngle is on.
private bool isRefreshingWhen set, stops UpdateScroller and Refresh from doing anything.
private bool isUsingDebugLeverAngleEditor testing: use debugLeverAngle instead of the lever.
private bool jumpToSelectedInspector button that runs JumpToSelected.
private SelectionLever leverThe selection lever that drives the scroller.
private static Logger loggerNLog logger for this class.
private float middleAngleThe lever's resting angle (its first selection angle).
private float negativeRangeHow far the lever can move below middleAngle.
private int numberOfSidesNumber of sides on the drum (default 6).
private float positiveRangeHow far the lever can move above middleAngle.
private string[] possibleValuesBacking field for PossibleValues.
private Transform scrollerThe drum transform that gets rotated.
private AnimationCurve speedCurveMaps how far the lever is pushed (0 to 1) to spin speed.
private float speedMultiplierScales the spin speed from speedCurve.
private List<TextRenderer> textSidesText renderers on each side of the drum.
private IUnityUpdateMethod updateHandle for the registered late update method while the lever is held.
private TextRenderer valueTextOptional text that shows the selected value.

Properties​

MemberWhat it is
int CurrentEnumIndex { get; protected set; }Index of the selected entry in PossibleValues.
string CurrentValue { get; }The selected string from PossibleValues.
string[] PossibleValues { get; set; }The list of strings the scroller cycles through.

Events​

MemberWhat it is
event Action<CustomScroller, int> IndexChangedRaised with the scroller and new index whenever the selection changes.

Methods​

MemberWhat it is
void UpdateTextSides()Puts the previous, current and next values on the three visible drum sides.
protected void Refresh()Wraps the current index, raises IndexChanged and updates the value text. Does nothing while isRefreshing is set.
protected virtual void UpdateText()Writes the selected value to valueText. Virtual so subclasses can show it differently.
protected int WrapEnumIndex(int index)Wraps an index into the range of PossibleValues.
9 private and internal methods
MemberWhat it is
private void Awake()Hooks the lever handle's interaction start and end to start and stop the scroller update.
private void JumpToSelected()Snaps the drum rotation to the selected panel.
private void SetScrollerRotation(float angle)Sets the drum's local rotation around X to the given angle.
private void Start()Works out the angle per side and the lever's ranges around its middle position, then snaps to the selection.
private void StartUpdatingScroller(Interactable arg1, Interactor arg2)Registers UpdateScroller in late update when the lever is grabbed.
private void StopUpdatingScroller(Interactable arg1, Interactor arg2)Stops the late update and snaps to the selected panel when the lever is let go.
private void UpdateScroller()Spins the drum based on how far the lever is from centre (through speedCurve), and steps the selection when the drum passes a side.
private void UpdateScroller(int direction)Spins the drum based on how far the lever is from centre (through speedCurve), and steps the selection when the drum passes a side.
private int WrapIndex(int number, int length)Wraps a number into 0 to length, handling negatives.

Used in​

Members of other types that take, return or hold a CustomScroller: