Game.UI.Widgets.IntFieldBuilders
Assembly:
Assembly-CSharp (Game)
Namespace:
Game.UI.Widgets
Type:
class
Base:
IFieldBuilderFactory
Summary:
IntFieldBuilders is a factory that produces FieldBuilder delegates for integer-like fields (primitive integer types and Unity integer vector types). It inspects the requested member type and optional widget attributes to decide which widget to create (IntInputField, IntSliderField, or a typed IntField
Fields
private static readonly int kGlobalValueRange
Defines a global clamped range (10,000,000) for numeric widgets. Unless EditorGenerator.sBypassValueLimits is true, requested min/max ranges will be clamped to [-kGlobalValueRange, kGlobalValueRange] to avoid exposing excessively large ranges in UI.
Properties
- This type exposes no public properties.
Constructors
public IntFieldBuilders()
Implicit parameterless constructor (no custom initialization in source). Use the class by instantiating it and calling TryCreate.
Methods
public FieldBuilder TryCreate(Type memberType, object[] attributes)
Attempts to create a FieldBuilder for the given memberType. Supported types:- byte, sbyte, short, ushort, int
- int2, int3, int4 (Unity.Mathematics)
- Vector2Int, Vector3Int (UnityEngine)
Behavior:
- For primitive integer types (byte, sbyte, short, ushort, int) it calls a specialized CreateIntFieldBuilder that takes explicit min/max bounds and converter delegates to/from int.
- For vector integer types it calls the generic CreateIntFieldBuilder
Note: TryCreate contains multiple local static helper functions (ToByte/FromByte, ToSByte/FromSByte, ToShort/FromShort, ToUShort/FromUShort, ToInt/FromInt, ToInt2/FromInt2, ToInt3/FromInt3, ToInt4/FromInt4, ToVector2Int/FromVector2Int, ToVector3Int/FromVector3Int). These are small converters used to construct CastAccessor instances.
private static FieldBuilder CreateIntFieldBuilder(object[] attributes, int min, int max, Converter<object, int> fromObject, Converter<int, object> toObject)
Creates a FieldBuilder for scalar integer-backed widgets (IntInputField or IntSliderField). Behavior/details:- Applies global clamping of min/max using kGlobalValueRange unless EditorGenerator.sBypassValueLimits is true.
- Reads step from attributes via WidgetAttributeUtils.GetNumberStep(attributes, 1).
- If value limits are not bypassed and WidgetAttributeUtils.GetNumberRange(attributes, ref min, ref max) returns true and WidgetAttributeUtils.RequiresInputField(attributes) is false, a slider (IntSliderField) is returned; the slider also gets a unit string from WidgetAttributeUtils.GetNumberUnit(attributes).
- Otherwise an IntInputField is returned.
-
The created widget receives a CastAccessor
that uses provided fromObject and toObject converters to bridge the widget's int API and the underlying boxed field. -
private static FieldBuilder CreateIntFieldBuilder<TWidget, TValue>(object[] attributes, Converter<object, TValue> fromObject, Converter<TValue, object> toObject) where TWidget : IntField<TValue>, new()
Generic creation for typed integer vector widgets (TWidget is an IntFieldimplementation such as Int2InputField, Int3InputField, Int4InputField). Behavior/details: - Determines step via WidgetAttributeUtils.GetNumberStep(attributes, 1).
- Determines min and max using EditorGenerator.sBypassValueLimits to choose between unlimited int.MinValue/int.MaxValue and clamped [-kGlobalValueRange, kGlobalValueRange]. If value limits are not bypassed it also attempts to read per-field range via WidgetAttributeUtils.GetNumberRange.
- Constructs and returns a delegate that creates a new TWidget with min, max, step and an accessor: if conversion delegates are provided a CastAccessor
is constructed using them; otherwise a parameterless CastAccessor is used.
Usage Example
// Example: create a FieldBuilder for a plain int field and build a widget instance with an accessor.
var factory = new IntFieldBuilders();
object[] attributes = /* attributes read from reflection or empty array */ new object[0];
// Try to get a FieldBuilder for int
FieldBuilder builder = factory.TryCreate(typeof(int), attributes);
if (builder != null)
{
// Assume 'accessor' is an IValueAccessor instance that reads/writes the underlying int-backed value.
IValueAccessor accessor = /* get or create an accessor */;
var widget = builder(accessor); // returns an IntInputField or IntSliderField depending on attributes/range
// Cast to the expected widget type if needed:
var intInput = widget as IntInputField;
if (intInput != null)
{
// configure or add to UI, e.g. intInput.min, intInput.max already set by the builder
}
}
Notes and tips: - WidgetAttributeUtils and EditorGenerator.sBypassValueLimits control whether sliders are created and whether global clamping applies. Provide appropriate attributes (range/step/unit) to obtain sliders with correct ranges and units. - When adding support for additional numeric types, provide matching converters and appropriate widget types (or reuse the scalar CreateIntFieldBuilder for single-integer primitives).