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.
- Listed in Global namespace: C to D
- Inherits or implements
MonoBehaviour
Constructors
| Member | What it is |
|---|---|
DialSetting() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
16 private and internal fields
| Member | What it is |
|---|---|
private Transform center | Pivot the angle is measured around and where the handle snaps back to. |
private float currentAngle | Current dial angle in degrees. |
private float currentValue | Backing field for Value. |
private Transform dial | Transform rotated to show the angle. |
private string format | Number format for the text, F1 by default. |
private Pickup grab | The pickup the player grabs to turn the dial. |
private bool isWholeNumbers | Whether to round the value to whole numbers. |
private float maxAngle | Angle for maxValue (150 by default). |
private float maxValue | Value at maxAngle. |
private float minAngle | Angle for minValue (-150 by default). |
private float minValue | Value at minAngle. |
private Vector3 offset | Selector position relative to the centre. |
private float range | Total angle range. |
private Transform selector | Point whose angle around the centre sets the value. |
private TextRenderer text | Text that shows the value. |
private IUnityUpdateMethod update | The late update registration while held. |
Properties
| Member | What it is |
|---|---|
float Value { get; } | The dial's current value. |
Events
| Member | What it is |
|---|---|
event Action<DialSetting, float, float> ValueChanged | Raised with the dial, old value and new value each update while held, even if unchanged. |
Methods
9 private and internal methods
| Member | What 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. |