EditorWindow
- Game Development course
- Expert
- Lesson 32/47
- 4 min
Learn to create a custom window with EditorWindow.
Independent Windows with EditorWindow
To create standalone, dockable windows like the Inspector or Hierarchy within the Unity interface, inherit from the EditorWindow class. The window is opened and brought to focus using the EditorWindow.GetWindow() method.
public class MapTool : EditorWindow
{
// The window is opened using GetWindow
}Rendering Window UI with OnGUI
The contents of an EditorWindow are rendered every frame inside its OnGUI() method. Layout utility classes such as GUILayout or EditorGUILayout are used to create buttons, sliders, and input fields.
void OnGUI()
{
GUILayout.Label("Map Settings");
}Practice Show Editor Window
Open the window on screen by calling the win.Show(); method.
Starter code
using System;
public class EditorWindow
{
public string title = "Harita";
public void Show() => Console.WriteLine("Pencere: " + title);
}
public class Program
{
public static void Main()
{
EditorWindow win = new EditorWindow();
// Pencereyi ekranda goster
}
}Sample solution
using System;
public class EditorWindow
{
public string title = "Harita";
public void Show() => Console.WriteLine("Pencere: " + title);
}
public class Program
{
public static void Main()
{
EditorWindow win = new EditorWindow();
win.Show();
}
}Expected output
Pencere: Harita
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which base class is inherited from to design a custom draggable window that docks into panels in the Unity editor?
- MonoBehaviour
- ScriptableObject
- Component
- EditorWindow Correct answer
Explanation: To create standalone, dockable editor windows, derive from the EditorWindow class.
2 Inherit from EditorWindow
public class BolumAraci : ____ {}
public class BolumAraci : EditorWindow {}
Explanation: To create a custom editor window, inherit from the EditorWindow class.
3 Window Architecture Terminology
| Term | Meaning |
|---|---|
EditorWindow |
Dockable custom window class in Unity |
GetWindow |
Opens or focuses an existing window |
OnGUI |
Method where window UI is drawn |
EditorGUILayout |
Class drawing auto-layout editor GUI |