Skip to main content

DialSetting

A class in Root.Township, the global namespace.

A grabbable dial that maps its angle to a number between a min and max, shows it on a TextRenderer, and raises ValueChanged. Local to whoever turns it; nothing is synced here.

Constructors​

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

Fields​

16 private and internal fields
MemberWhat it is
private Transform centerPivot the angle is measured around and where the handle snaps back to.
private float currentAngleCurrent dial angle in degrees.
private float currentValueBacking field for Value.
private Transform dialTransform rotated to show the angle.
private string formatNumber format for the text, F1 by default.
private Pickup grabThe pickup the player grabs to turn the dial.
private bool isWholeNumbersWhether to round the value to whole numbers.
private float maxAngleAngle for maxValue (150 by default).
private float maxValueValue at maxAngle.
private float minAngleAngle for minValue (-150 by default).
private float minValueValue at minAngle.
private Vector3 offsetSelector position relative to the centre.
private float rangeTotal angle range.
private Transform selectorPoint whose angle around the centre sets the value.
private TextRenderer textText that shows the value.
private IUnityUpdateMethod updateThe late update registration while held.

Properties​

MemberWhat it is
float Value { get; }The dial's current value.

Events​

MemberWhat it is
event Action<DialSetting, float, float> ValueChangedRaised with the dial, old value and new value each update while held, even if unchanged.

Methods​

9 private and internal methods
MemberWhat it is
private void ClampDial()Rotates the dial to the current angle and snaps the grab handle back to the centre.
private void OnValidate()Recomputes the angle range.
private void OnValueChanged(float oldValue, float newValue)Raises ValueChanged with old and new values.
private void ResetGrab(Interactable arg1, Interactor arg2)On release, stops updating and puts the handle back at the centre, kinematic.
private void Setup()Works out the angle range from minAngle and maxAngle.
private void Start()Hooks the grab's interaction events and sets up the range.
private void StartUpdating(Interactable arg1, Interactor arg2)On grab, starts updating the dial every late update.
private void UpdateDial()Updates the value and then the dial.
private void UpdateValue()Reads the selector's angle around the centre, clamps it, maps it to a value, rounds if needed and updates the text.