Drawing the default inspector with UIElements/UI Builder

Viewed 1032

I have a LevelEditor script which has a custom inspector editor built with UIBuilder and UIElements. The problem is that i would like to cache references inside a list but i do not want to make a custom list view for it (it's kinda hard to implement in UIElements and not worth the time) so i thought i would just make the private List<MyType> _myVar; as [Serializefield] and then draw the DefaultInspector below the custom one.

I found a method that does this DrawDefaultInspector but unfortunately it does nothing.

public override VisualElement CreateInspectorGUI()
{
    _visualTree.CloneTree(_rootElement);

    // My custom editor code
    ...

    DrawDefaultInspector();

    return _rootElement;
}

Any help is appreciated...

1 Answers

You need to place an IMGUIContainer via UIBuilder (or by code via _rootElement.Add(IMGUIVisualElement)) and than do the following inside CreateInspectorGUI

public override VisualElement CreateInspectorGUI()
{
    _visualTree.CloneTree(_rootElement);

    // Your custom editor code
    ...

    // Drawing the default inspector
    var defaultInspector = _rootElement.Q<IMGUIContainer>();
    defaultInspector.onGUIHandler = () => DrawDefaultInspector();

    return _rootElement;
}

What i usually do is placing the DefaultInspector in a foldout too so designers can use the custom Inspector but whenever they need some advanced stuff that ain't visible to them they can use the default inspector.

So a layout like this will appear to them (default inspector is hidden by default ofc :) ) enter image description here

Related