Unity inspector in custom window

I have a custom window that displays a list of objects. Each of these objects has its own inspector editor.

Is it possible to show a custom inspector inside a custom window?

+5
source share
1 answer

You cannot force Unity3Dyour inspector to draw anywhere else than the inspector window.

You can manually install BtwEditor using the Editor.CreateEditor method . Since you are showing a user inspector, it must be created to create it manually from the method Window.OnGUIand use the public OnInspectorGUIeditor method to draw the editor inside your window.

, script CustomScript GameObject Editor CustomScriptEditor, , GameObject , EditorWindow:

using UnityEditor;
using UnityEngine;


public class TestWindow : EditorWindow
{

    [MenuItem ("Window/Editor Window Test")]
    static void Init () 
    {
        // Get existing open window or if none, make a new one:
        TestWindow window = (TestWindow)EditorWindow.GetWindow (typeof (TestWindow));
    }

    void OnGUI () {

        GameObject sel = Selection.activeGameObject;

        CustomScript targetComp = sel.GetComponent<CustomScript>();

        if (targetComp != null)
        {
            var editor = Editor.CreateEditor(targetComp);
            editor.OnInspectorGUI();            
        }

    }
}
+5

All Articles