Skip to main content

StandardFloatAsEnum

A class in Root.Township, Alta.Menu.

Client menu control that shows a float setting as a drum of named choices, spun with a lever like ScrollerEnumMenuSetting. The choices come from an EnumFloatGameSettingsAccess or its own lists.

Constructors​

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

Fields​

MemberWhat it is
protected bool isRefreshingTrue while the current choice is being loaded; blocks changes.
22 private and internal fields
MemberWhat it is
private float anglePerSideDegrees between drum faces (360 divided by numberOfSides).
private float currentAngleThe drum's current rotation in degrees.
private int currentlySelectedPanelIndex of the drum face that is selected.
private float debugLeverAngleLever angle used instead of the real one when isUsingDebugLeverAngle is on.
private EnumFloatGameSettingsAccess enumSettingsThe setting as an EnumFloatGameSettingsAccess, when it is one; supplies the values and names.
private bool isUsingDebugLeverAngleDebug option to drive the drum from debugLeverAngle.
private bool isUsingEnumSettingsTrue when the choices come from enumSettings instead of this component's lists.
private bool jumpToSelectedInspector button that snaps the drum to the selected face.
private SelectionLever leverThe lever that drives the drum. Must have one selection option, in the middle.
private static Logger loggerNLog logger for this class.
private float middleAngleThe lever's resting angle.
private float negativeRangeLever travel below the middle angle.
private int numberOfSidesNumber of faces on the drum. Default 6.
private float positiveRangeLever travel above the middle angle.
private float[] possibleValuesFloat values for each choice when no enum settings source is used. Default 0.5, 1, 2, 4.
private string[] possibleValuesNamesNames shown for each choice when no enum settings source is used.
private Transform scrollerThe drum transform that rotates.
private AnimationCurve speedCurveMaps how far the lever is pushed (0 to 1) to spin speed.
private float speedMultiplierMultiplier on the spin speed.
private List<TextRenderer> textSidesText on each drum face.
private IUnityUpdateMethod updateThe registered late update while the lever is held.
private TextRenderer valueTextSerialized text field that this class never writes to.

Properties​

MemberWhat it is
int CurrentIndex { get; protected set; }Index of the selected choice, or -1 if the setting's value matches none of them.

Methods​

MemberWhat it is
void GoToNextValue()Steps to the next choice and saves it to the setting.
void GoToPreviousValue()Steps to the previous choice and saves it to the setting.
protected override void OnValidate()Editor: names the object, logs an error if the lever has more than one option, and handles the jump button.
protected void Refresh()Wraps CurrentIndex and writes that choice's value to the setting. Does nothing while the index is -1.
protected override void Setup()Picks the enum settings source if the setting has one, works out the drum and lever angles, then loads the current choice.
protected int WrapEnumIndex(int index)Wraps a choice index past the end back to 0; any negative index becomes the last choice.
12 private and internal methods
MemberWhat it is
private void Awake()Starts and stops scrolling when the lever handle is grabbed and let go.
private void FinishedRefresh()Snaps the drum to the selected face and fills in the face texts.
private int GetIndex()Finds the choice whose value is about equal to the setting's current value; -1 if none.
private void JumpToSelected()Rotates the drum to show the selected face squarely.
private void RefreshValues()Sets CurrentIndex from the setting's value, then calls FinishedRefresh.
private void SetScrollerRotation(float angle)Sets the drum's local x rotation.
private void StartUpdatingScroller(Interactable arg1, Interactor arg2)Starts calling UpdateScroller every late update while the lever is held.
private void StopUpdatingScroller(Interactable arg1, Interactor arg2)Stops the late update and snaps the drum to the selected face.
private void UpdateScroller()Spins the drum by the lever's angle through speedCurve; when it passes a face, steps the choice and saves it.
private void UpdateScroller(int direction)Spins the drum by the lever's angle through speedCurve; when it passes a face, steps the choice and saves it.
private void UpdateTextSides()Writes the previous, current and next choice names on the three drum faces around the selected one.
private int WrapIndex(int number, int length)Wraps a number into the range 0 to length minus 1.