Skip to content

Game.UI.Widgets.ToggleFieldBuilders

Assembly:
Assembly-CSharp (game/runtime assembly where UI widget types reside)

Namespace:
Game.UI.Widgets

Type:
public class

Base:
IFieldBuilderFactory

Summary:
A small factory that creates FieldBuilder instances for boolean fields. When asked to create a builder for a member of type System.Boolean, it returns a FieldBuilder configured to produce a ToggleField. For any other member type it returns null, indicating this factory does not handle that type. The attributes array parameter is accepted but not used by this implementation.


Fields

  • This class declares no instance or static fields.
    ToggleFieldBuilders has no backing state; it is a stateless factory.

Properties

  • This class declares no public properties.
    It only implements the factory method from IFieldBuilderFactory.

Constructors

  • public ToggleFieldBuilders()
    Creates a new instance of the ToggleFieldBuilders factory. The default parameterless constructor is used (no initialization required because the class is stateless).

Methods

  • public FieldBuilder TryCreate(Type memberType, object[] attributes)
    Attempts to create a FieldBuilder for the requested member type.

  • Parameters:

    • memberType — The System.Type of the member for which a field builder is requested.
    • attributes — An array of attribute instances applied to the member (ignored by this implementation).
  • Behavior:
    • If memberType is typeof(bool) (System.Boolean), returns the result of WidgetReflectionUtils.CreateFieldBuilder(), which is a FieldBuilder specialized to create ToggleField widgets bound to bool values.
    • Otherwise returns null to indicate this factory cannot create a builder for the given type.
  • Remarks:
    • The attributes parameter is present to allow other factories to react to attributes (e.g., custom editors), but ToggleFieldBuilders does not inspect or use attributes.
    • No exceptions are thrown by the method as implemented; it returns null for unsupported types.

Usage Example

// Create the factory
var factory = new Game.UI.Widgets.ToggleFieldBuilders();

// Request a builder for a bool member
FieldBuilder builder = factory.TryCreate(typeof(bool), new object[0]);

if (builder != null)
{
    // builder is configured to create ToggleField widgets for bool properties/fields
    // Use builder according to the UI framework's FieldBuilder usage patterns
}

// For non-bool types you will get null
FieldBuilder other = factory.TryCreate(typeof(int), new object[0]); // returns null

Notes: - This factory is suitable to register with any system that expects IFieldBuilderFactory implementations so boolean properties/fields are displayed as toggle controls in the UI. - If you need attribute-driven behavior (e.g., customizing label, tooltip, or layout) extend this factory to inspect the attributes array and pass the information to the created FieldBuilder.