Game.UI.Widgets.IEditorGenerator
Assembly:
(assembly inferred from project; commonly Assembly-CSharp or Game.dll)
Namespace: Game.UI.Widgets
Type: Interface
Base: None (interface)
Summary:
IEditorGenerator defines a contract for building editor UI widgets for a given value accessor and associated attributes. Implementers return an IWidget instance that represents the editor control for the target value. The interface is used by the in-game editor/UI system to construct property editors dynamically based on metadata and attributes.
Fields
- (none)
No fields are declared on this interface.
Properties
- (none)
This interface does not declare properties.
Constructors
- (none)
Interfaces do not have constructors.
Methods
-
IWidget Build(IValueAccessor accessor, object[] attributes, int level, string path)
Builds and returns an editor widget for the provided accessor. -
Parameters:
accessor
(NotNull) — An IValueAccessor providing get/set access to the value being edited. Implementations should use this to read and write the target value.attributes
(NotNull) — Array of attribute objects that describe metadata for the editor (for example custom UI attributes). These typically come from reflection of the target field/property and can influence widget creation.level
— Integer representing the nesting level or indentation depth in the editor layout. Used to adjust layout/indentation or choose different widget styles for nested items.path
— String path identifying the property (for example a hierarchical property path). Useful for telemetry, binding keys, or resolving context.
-
Returns:
IWidget
— A widget instance representing the editor control for the given accessor and attributes.
-
Notes:
- Parameters in the original source are annotated with [NotNull], so callers expect non-null values for accessor and attributes.
- Implementations should create widgets on the UI/main thread and ensure proper hooking of accessor get/set operations.
- The interface is typically used by reflection-driven UI systems to provide per-type or per-attribute custom editors.
Usage Example
// Example implementation of IEditorGenerator
public class StringEditorGenerator : IEditorGenerator
{
public IWidget Build(IValueAccessor accessor, object[] attributes, int level, string path)
{
// Create a simple text field widget (pseudo-code — replace with actual widget creation API)
var textField = new TextFieldWidget();
// Initialize with current value
textField.Text = accessor.GetValue()?.ToString() ?? string.Empty;
// Update accessor when the text changes
textField.OnTextChanged += newText =>
{
accessor.SetValue(newText);
};
// Optionally inspect attributes to alter behavior
// e.g. if attributes contain a MaxLength attribute, apply it:
// var maxAttr = attributes.OfType<MaxLengthAttribute>().FirstOrDefault();
// if (maxAttr != null) textField.MaxLength = maxAttr.Length;
// Use level/path for layout or naming if needed
textField.Name = $"editor_{path.Replace('.', '_')}_lvl{level}";
return textField;
}
}
Notes: - Replace TextFieldWidget and event hookups with the actual IWidget implementations and APIs provided by the game's UI framework. - Ensure created widgets properly subscribe/unsubscribe to avoid leaks and behave correctly when values update from code.