Skip to content

Game.UI.Widgets.PopupValueFieldBuilders

Assembly:
Game

Namespace: Game.UI.Widgets

Type:
public class PopupValueFieldBuilders

Base:
IFieldBuilderFactory

Summary:
Provides a field-builder factory that creates popup-based value fields for members whose type is (or derives from) PrefabBase. When TryCreate is called with a memberType assignable from PrefabBase, it returns a FieldBuilder delegate that, given an IValueAccessor, wraps it in a CastAccessor and constructs a PopupValueField wired to a PrefabPickerPopup for the requested member type. If the memberType is not a PrefabBase (or derived), TryCreate returns null.


Fields

  • This class declares no instance or static fields.
    The factory is stateless; it returns delegates which close over the provided memberType.

Properties

  • This class declares no properties.

Constructors

  • public PopupValueFieldBuilders()
    This class relies on the default parameterless constructor (compiler-provided). No initialization logic is required because the factory has no instance state.

Methods

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

Behavior details: - If memberType is assignable from PrefabBase (i.e., typeof(PrefabBase).IsAssignableFrom(memberType)), the method returns a FieldBuilder delegate: - The delegate takes an IValueAccessor (runtime accessor for the field value). - It wraps the accessor in a CastAccessor so the accessor exposes PrefabBase-typed values. - It constructs and returns a new PopupValueField with: - accessor = the CastAccessor instance - popup = new PrefabPickerPopup(memberType) — the popup is created for the concrete memberType so the picker can filter/instantiate the right prefab subtype. - If memberType is not assignable from PrefabBase, the method returns null indicating this factory cannot build a field for that type.

Notes and dependencies: - Requires the following types/namespaces: PrefabBase (Game.Prefabs), CastAccessor (Game.Reflection), PopupValueField and PrefabPickerPopup (Game.UI.Editor). - The returned FieldBuilder closes over memberType; be mindful if memberType is a dynamically generated type. - This method does not inspect the attributes array; custom attribute-driven behavior is not implemented here. - No exceptions are thrown explicitly; potential exceptions could occur during construction of CastAccessor or PrefabPickerPopup if those types throw for invalid input.

Usage Example

// Example: using the factory to build a field for a PrefabBase-derived member.
var factory = new PopupValueFieldBuilders();
Type memberType = typeof(MyCustomPrefab); // MyCustomPrefab : PrefabBase
FieldBuilder builder = factory.TryCreate(memberType, attributes: null);

if (builder != null)
{
    IValueAccessor accessor = /* obtain accessor for the field at runtime */;
    var field = builder(accessor); // returns PopupValueField<PrefabBase>
    // field.accessor is a CastAccessor<PrefabBase>
    // field.popup is a PrefabPickerPopup configured for MyCustomPrefab
}
else
{
    // The factory cannot build a field for the requested type.
}

{{ - Purpose: Simplify creation of prefab-picker popup fields in editor UIs by providing a reusable factory for PrefabBase-derived member types. - Typical usage context: UI/editor code that dynamically builds inspector fields for game objects or asset references in Cities: Skylines 2 modding tools. - Extensibility: If you need popup fields for other types, implement a factory following IFieldBuilderFactory or extend this factory to handle additional base types or attribute-driven customization. }}