Game.UI.Widgets.FloatFieldBuilders
Assembly:
Assembly-CSharp (game runtime)
Namespace:
Game.UI.Widgets
Type:
public class
Base:
IFieldBuilderFactory
Summary:
FloatFieldBuilders is a factory used by the UI/editor generator to produce FieldBuilder delegates for numeric/value types (float, double, Unity.Mathematics float2/float3/float4, UnityEngine Vector2/Vector3/Vector4, quaternion/Quaternion). It inspects the requested member type and optional widget attributes to return a FieldBuilder that constructs either an input field or a slider-like field (or a specialized multi-component Float field widget). The factory adjusts and clamps numeric ranges based on global limits and WidgetAttribute metadata, and uses conversion/accessor wrappers (CastAccessor) to adapt underlying IValueAccessor values to the widget's expected value type.
Key behaviors:
- Supports float, double, float2/3/4, Vector2/3/4, quaternion/Quaternion.
- Uses WidgetAttributeUtils to determine step, range, and unit. If a numeric range is provided and input-field is not explicitly required, it will prefer a slider-style field (FloatSliderField) for single-valued types.
- All range limits are clamped to +/- 10,000,000 (kGlobalValueRange) unless EditorGenerator.sBypassValueLimits is true.
- Provides conversion wrappers between different numeric/engine/math types using CastAccessor.
- Contains generic CreateFloatFieldBuilder overload for multi-component fields (TWidget : FloatField
Fields
private const double kGlobalValueRange = 10000000.0
Used as a global clamp for numeric ranges (positive and negative). When EditorGenerator.sBypassValueLimits is false, min/max ranges for created widgets are clamped inside ±kGlobalValueRange to prevent extremely large ranges from being exposed in the UI.
Properties
- This type exposes no public properties.
Constructors
public FloatFieldBuilders()
No explicit constructor is defined in source; the compiler-provided default parameterless constructor is used.
Methods
-
public FieldBuilder TryCreate(Type memberType, object[] attributes)
Main entry point. Returns a FieldBuilder delegate tailored to the requested memberType (or null if the type is not handled). Supported types include float, double, float2/float3/float4 (Unity.Mathematics), Vector2/3/4 (UnityEngine), quaternion, and Quaternion. The method defines several local converter functions (ToFloat, FromFloat, ToDouble, FromDouble, ToVector/FromVector, ToVector3/FromVector3, ToVector4/FromVector4, ToEulerAngles/FromEulerAngles, etc.) and passes appropriate converters into the helper CreateFloatFieldBuilder overloads. -
private static FieldBuilder CreateFloatFieldBuilder(object[] attributes, double min, double max, Converter<object, double> fromObject, Converter<double, object> toObject)
Helper for single-value numeric types (float/double). Applies global-range clamping (unless EditorGenerator.sBypassValueLimits is set), reads step from attributes (default 0.01), and if a numeric range is present and a slider is allowed (WidgetAttributeUtils.GetNumberRange returns true and RequiresInputField is false), it returns a builder that produces FloatSliderField instances (configured with min/max/step/unit and a CastAccessor). Otherwise returns a builder that produces FloatInputField (min/max/step and CastAccessor). -
private static FieldBuilder CreateFloatFieldBuilder<TWidget, TValue>(object[] attributes, Converter<object, TValue> fromObject = null, Converter<TValue, object> toObject = null) where TWidget : FloatField<TValue>, new()
Generic helper for multi-component float fields (e.g., Float2InputField, Float3InputField, Float4InputField, EulerAnglesField). Reads a per-component float4 min/max defaulted to ±kGlobalValueRange, reads step from attributes, applies WidgetAttributeUtils.GetNumberRange to possibly override per-component ranges, and returns a builder that constructs TWidget instances. The created widget gets a CastAccessorif converters are supplied; otherwise a default CastAccessor . If EditorGenerator.sBypassValueLimits is false, the widget's min/max values are set via TWidget.ToFieldType(min/max).
Notes about converters and accessors: - CastAccessor is used to adapt the IValueAccessor (which operates on the underlying object type) to the field widget's expected numeric type. Converters are provided where required (for example, converting Quaternion ↔ float3 Euler angles).
Usage Example
// Example: creating a FloatFieldBuilder for a float member and constructing a widget
var factory = new FloatFieldBuilders();
object[] attributes = new object[0]; // or attributes discovered via reflection
FieldBuilder builder = factory.TryCreate(typeof(float), attributes);
if (builder != null)
{
IValueAccessor accessor = /* obtain an accessor for the target value */;
var widget = builder(accessor); // widget will be a FloatInputField or FloatSliderField depending on attributes
// Configure or add widget to UI...
}
Additional notes: - If you need Euler angle editing for quaternion/Quaternion members, FloatFieldBuilders will create an EulerAnglesField that converts between quaternion/Quaternion and float3 Euler angles using Quaternion.Euler and .eulerAngles. - The factory relies on WidgetAttributeUtils and EditorGenerator.sBypassValueLimits; these influence when sliders are used and the allowable min/max values.