menu_bookDocumentation
Custom Editors
Custom Editors
Create custom editor widgets for your classes, structs, and assets.
ControlWidget (Property Editor)
Create custom property editors using [CustomEditor]:
CSHARP
public class MyClass
{
public Color Color { get; set; }
public string Name { get; set; }
}
[CustomEditor(typeof(MyClass))]
public class MyCustomControlWidget : ControlObjectWidget
{
public override bool SupportsMultiEdit => false;
public MyCustomControlWidget(SerializedProperty property) : base(property)
{
Layout = Layout.Row();
Layout.Spacing = 2;
// Get properties
SerializedObject.TryGetProperty(nameof(MyClass.Color), out var color);
SerializedObject.TryGetProperty(nameof(MyClass.Name), out var name);
// Add controls
Layout.Add(Create(color));
Layout.Add(Create(name));
}
protected override void OnPaint()
{
// Empty to prevent default background
}
}Attribute-Specific Editors
Create editor only for properties with specific attributes:
CSHARP
[CustomEditor(typeof(string), WithAllAttributes = new[] { typeof(PasswordAttribute) })]
public class PasswordEditor : ControlWidget { ... }InspectorWidget (Full Inspector)
Replace entire inspector for assets or tools:
CSHARP
[CanEdit("asset:char")] // For .char assets
public class CharacterInspector : Widget, IAssetInspector
{
CharacterResource Character;
ControlSheet MainSheet;
public CharacterInspector(Widget parent) : base(parent)
{
// Build custom UI
}
public void SetAsset(Asset asset)
{
// Load and display asset
}
}Key Classes
| Class | Purpose |
|---|---|
| ControlWidget | Single property editor |
| ControlObjectWidget | Object with multiple properties |
| InspectorWidget | Full inspector replacement |
| ControlSheet | Automatic form layout |
Was this helpful?