Engines‎ > ‎Unity‎ > ‎

Editor Window

I have a BrainSpy window to see what the agents in our game are dreaming about
They dream about Electric Sheep

In unity one can create custom editor windows. For example to display the AI state of the selected enemy. The window is created by creating a class that inherit from EditorWindow and then put that file in the Assets/Editor directory. To display the window use the MenuItem attribute in the class.

SimpleEdit.cs
This is a minimal editor window that can be opened with the MyEditor/SimpleEdit menutiem. It display the name of the selected object.

using UnityEngine;
using UnityEditor;

public class SimpleEdit : EditorWindow
{
    [MenuItem ("MyEditor/SimpleEdit")]
    static void Init () {
        EditorWindow.GetWindow (typeof (SimpleEdit));
    }

    private void OnGUI()
    {
        if (Selection.activeGameObject == null)
        {
            GUILayout.Label("Selected: No GameObject", EditorStyles.boldLabel);
            return;
        }

        GUILayout.Label("Selected: " + Selection.activeGameObject.name, EditorStyles.boldLabel);
    }

    void OnInspectorUpdate()
    {
        Repaint();
    }
}




Comments