Vixen
02b45cc4
csharp
public record class CustomInspector

A hand-written inspector for one type, instead of the rows the generator would produce.

Read the guide page for this →

Remarks

F5: there was no path at all. The descriptor generator is a ProjectReference analyzer and there was no attribute-scanned runtime path either, so nothing outside this repository could replace an inspector for its own type. This is the contribution that answers it, through EditorRegistry, so a plugin, a generated registration and a project script are indistinguishable to the panel.

⚠ It is handed an EditTarget and not the objects. That is what makes a custom inspector as multi-object-aware, as undoable and as mixed-value-correct as the generated one without writing any of it: target.Find("Roughness") is a binding over however many objects are selected. A custom inspector that reached for target.Objects[0] and assigned a field would lose all of it, which is precisely Unity's warning about not going around SerializedObject.

The generated rows are still reachable — InspectorRows.Add builds one from a field — so the ordinary shape of a custom inspector is "the usual rows, in my order, with my two buttons between them" rather than a panel written from nothing.

Fields and properties (3)

  • public Type Target

    The type it draws. Exactly that type — a subclass gets the generated rows.

  • public Action<UiElement, EditTarget> Build

    Fills the panel's body from what is being edited. Called once per selection, and what it puts there replaces the whole row list. ⚠ It fills a container rather than returning one, which is where this differs from Unity's CreateInspectorGUI. A UiElement in this framework is created by its parent — Document.Create(tag, parent, …) — so there is no detached element to hand back. Every other builder in the editor has the same shape; PanelDescriptor takes an Action<DockPanel> for the same reason.

  • public int Order

    Which wins when two are registered for one type, high first. A plugin overriding a built-in registers a higher one; ties go to whichever registered last, so a project's own beats a package's by arriving later.

Methods (1)

  • public CustomInspector(Type Target, Action<UiElement, EditTarget> Build, int Order = 0)

    A hand-written inspector for one type, instead of the rows the generator would produce.

Used by (5)

  • DeclaredContributionTestsVixen.Editor.App.Tests
  • DeclaredContributionsVixen.Editor.App
  • InspectorViewVixen.Editor.Inspector
  • OutOfTreePluginTestsVixen.Editor.App.Tests
  • TerrainModuleVixen.Editor.Terrain