Game.UI.Debug.DebugWidgetBuilders
Assembly: Assembly-CSharp (game)
Namespace: Game.UI.Debug
Type: public static class
Base: System.Object
Summary:
Utility/ factory class that converts in-game DebugUI widget definitions (DebugUI.Widget and its derived types) into UI runtime widgets (IWidget implementations) used by the game's UI system. It filters out editor-only widgets, localizes display names for INamed widgets, and maps each DebugUI widget type to an appropriate IWidget with accessors, sliders, flags, enums, color pickers, etc. The class is stateless and safe to call from UI construction code.
Fields
- None.
This static class does not declare any fields.
Properties
- None.
No properties are exposed.
Constructors
- None.
Static classes do not provide constructors.
Methods
-
public static IEnumerable<IWidget> BuildWidgets(ObservableList<DebugUI.Widget> debugWidgets)
Builds runtime widgets for a collection of DebugUI.Widget entries. Skips widgets marked as editor-only. For each built widget that implements INamed, sets its displayName to LocalizedString.Value(debugWidget.displayName). Returns a lazily-evaluated sequence (yield) of IWidget instances. -
[CanBeNull] private static IWidget TryBuildWidget(DebugUI.Widget debugWidget)
Attempts to map a single DebugUI.Widget instance to an IWidget. Returns the corresponding IWidget for recognized types (Foldout, Container, ValueTuple, Button, Value, BoolField, IntField, IntInputField, UIntField, FloatField, Vector2/3/4 fields, EnumField, BitField, ColorField, TextField). Returns null for unknown/unhandled types. -
private static ExpandableGroup BuildExpandableGroup(DebugUI.Foldout debugWidget)
Creates an ExpandableGroup whose open state is bound via a DelegateAccessorto debugWidget.opened. The group's children are built by calling BuildWidgets on the foldout's children. -
private static Group BuildGroup(DebugUI.Container debugWidget)
Creates a Group widget whose children are built from the container's children. -
private static Group BuildGroup(DebugUI.ValueTuple debugWidget)
Builds a Group of ValueField widgets from a DebugUI.ValueTuple. Uses parent DebugUI.Foldout column labels (if present) to set each ValueField.displayName. Each ValueField.path is set to the index position. -
private static Button BuildButton(DebugUI.Button debugWidget)
Creates a Button widget and binds its action to debugWidget.action. -
private static ValueField BuildValueField(DebugUI.Value debugWidget)
Creates a ValueField wrapper for a read-only value debug widget. -
private static ToggleField BuildToggleField(DebugUI.BoolField debugWidget)
Creates a ToggleField and sets its accessor to a DebugFieldAccessorbound to the debug widget. -
private static IntField<int> BuildIntField(DebugUI.IntField debugWidget)
Builds either an IntSliderField (when both min and max are provided) or an IntArrowField otherwise. Uses Invoke to read optional min/max functions. Uses DebugFieldAccessorfor access. -
private static UIntField BuildUIntField(DebugUI.UIntField debugWidget)
Similar to BuildIntField but for unsigned ints. Chooses between UIntSliderField and UIntArrowField based on min/max presence. Uses DebugFieldAccessor. -
private static FloatField<double> BuildFloatField(DebugUI.FloatField debugWidget)
Creates either a FloatSliderField (if min and max are provided) or a FloatArrowField otherwise. Uses DebugFieldCastAccessorto cast between the debug data type and the UI float type. Honors increment step and multiplier settings. -
private static Float2SliderField BuildFloat2Field(DebugUI.Vector2Field debugWidget)
Creates a Float2SliderField with a DebugFieldCastAccessoraccessor. Copies step, stepMultiplier, and decimal precision (fractionDigits). -
private static Float3SliderField BuildFloat3Field(DebugUI.Vector3Field debugWidget)
Creates a Float3SliderField with a DebugFieldCastAccessoraccessor. Copies step, stepMultiplier, and decimal precision. -
private static Float4SliderField BuildFloat4Field(DebugUI.Vector4Field debugWidget)
Creates a Float4SliderField with a DebugFieldCastAccessoraccessor. Copies step, stepMultiplier, and decimal precision. -
private static EnumField BuildEnumField(DebugUI.EnumField debugWidget)
Creates an EnumField and populates enumMembers via BuildEnumMembers. Binds the value with a DelegateAccessorthat reads debugWidget.GetValue() and sets debugWidget.SetValue(int). -
private static FlagsField BuildFlagsField(DebugUI.BitField debugWidget)
Creates a FlagsField for bit/flag enums. Attempts to get conversion delegates from EnumFieldBuilders.GetConverters; if absent, falls back to default conversions between object and ulong/long. Populates enumMembers with BuildEnumMembers and binds the value using a DelegateAccessorusing the converters. -
private static EnumMember[] BuildEnumMembers<T>(DebugUI.EnumField<T> debugWidget)
Builds an array of EnumMember entries from debugWidget.enumValues and debugWidget.enumNames. Each EnumMember stores the numeric (ulong) value and the displayed name text. -
private static ColorField BuildColorField(DebugUI.ColorField debugWidget)
Creates a ColorField, copying hdr and showAlpha flags, and binds via DebugFieldAccessor. -
private static StringInputField BuildStringInputField(DebugUI.TextField debugWidget)
Creates a StringInputField bound to the debug widget via DebugFieldAccessor. -
private static IntInputField BuildIntInputField(Game.Debug.IntInputField debugWidget)
Creates and returns an IntInputField initialized with the provided debugWidget (constructor usage depends on that type's implementation). -
private static T Invoke<T>(Func<T> func, T fallback)
Helper to safely invoke optional Func. Returns fallback when func is null; otherwise returns func().
Notes and dependencies: - This builder relies on many game-specific types: DebugUI.* types, IWidget and its implementations (Group, ExpandableGroup, Button, ValueField, ToggleField, IntSliderField, IntArrowField, UIntSliderField, UIntArrowField, FloatSliderField/ArrowField, Float2/3/4SliderField, EnumField, FlagsField, ColorField, StringInputField, IntInputField), accessors (DelegateAccessor, DebugFieldAccessor, DebugFieldCastAccessor), LocalizedString, EnumFieldBuilders, and EnumMember. - Widgets created by this builder typically bind directly to debugWidget getters/setters; modifications in the UI will affect the underlying debug objects. - The class filters out debugWidget.isEditorOnly entries and localizes display names for widgets that implement INamed.
Usage Example
// Given an ObservableList<DebugUI.Widget> debugWidgets (e.g., from a debug panel definition)
IEnumerable<IWidget> widgets = DebugWidgetBuilders.BuildWidgets(debugWidgets);
foreach (IWidget w in widgets)
{
// e.g., add to a parent group or UI container
parentGroup.children.Add(w);
}
This example demonstrates converting a DebugUI widget list to runtime IWidget instances that can be attached to the game's UI.