Game.UI.Widgets.RangedSliderField
Assembly:
Namespace: Game.UI.Widgets
Type: class
Base: FloatSliderField
Summary:
RangedSliderField is a UI slider widget specialized for float values. It extends a generic FloatSliderField
Fields
- No private fields are declared explicitly in the source file.
The class relies on inherited state and auto-properties.
Properties
-
protected override float defaultMin => float.MinValue
Sets the slider's default minimum to System.Single.MinValue. Used by the base FloatSliderField when no explicit minimum is provided. -
protected override float defaultMax => float.MaxValue
Sets the slider's default maximum to System.Single.MaxValue. Used by the base FloatSliderField when no explicit maximum is provided. -
public float[] ranges { get; set; }
Optional array of float values representing range markers or discrete allowed values. When serializing the widget, this array is written as the "ranges" JSON property. If null, an empty array is written. -
public Func<string> iconSrc { get; set; }
A delegate that should return the icon source string (e.g., resource path or name). When serializing, the result of calling iconSrc() is written as the "iconSrc" JSON property. Must be non-null at serialization time to avoid a NullReferenceException.
Constructors
public RangedSliderField()
No explicit constructors are defined in the source; the class uses the compiler-generated parameterless constructor. Initialization of ranges and iconSrc should be done after construction.
Methods
-
public override float ToFieldType(double4 value)
Converts a Unity.Mathematics.double4 to the slider's field type by returning (float)value.x. Only the x component is used; y/z/w are ignored. -
protected override void WriteProperties(IJsonWriter writer)
Serializes the widget-specific properties to JSON. Implementation: - Calls base.WriteProperties(writer) to write inherited properties.
- Writes a "ranges" property: computes num = (ranges != null) ? ranges.Length : 0, begins an array of that length, writes each ranges[i], then ends the array.
- Writes an "iconSrc" property whose value is the string returned by iconSrc().
Notes: - The method assumes iconSrc is assigned; calling WriteProperties when iconSrc is null will throw. - ranges being null results in an empty JSON array being written rather than omitting the property.
Usage Example
// Create and configure a RangedSliderField
var slider = new RangedSliderField();
// Define discrete ranges or markers
slider.ranges = new float[] { 0f, 10f, 50f, 100f };
// Provide an icon source provider (must not be null at serialization time)
slider.iconSrc = () => "Textures/MyMod/slider_icon";
// The slider can now be added to the UI and, when serialized, will include
// the "ranges" array and "iconSrc" string in its JSON representation.
Additional tips: - Ensure iconSrc is assigned before the UI system calls WriteProperties to avoid exceptions. - If you need different conversion behavior from double4, override ToFieldType accordingly. - The wide defaultMin/defaultMax values mean you should typically set explicit min/max on the instance if you want confined slider behavior.