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
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
Notes and dependencies:
- Requires the following types/namespaces: PrefabBase (Game.Prefabs), CastAccessor
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. }}