Game Development Reference
In-Depth Information
The editor window
Quite simply, Unity editor windows are just separate containers for collections of editor
GUI controls. These windows are a more advanced version of the property drawers de-
scribed previously, and as such use a different set of custom controls.
The
Inspector
,
Game
, and
Scene
windows, and in fact, pretty much every other dockable
window in the Unity editor, are editor windows. In fact, they are all built in the same way
using the same scripting framework.
Note
As stated previously, remember that any script that uses the editor functionality or the
UnityEditor
namespace must be placed in a special project folder titled
Editor
.
To implement your own editor window, you simply need to create a class that is derived
from
EditorWindow
instead of
MonoBehaviour
. The script must also live in the
special
Editor
folder within the project structure, so create a new script called
MyEd-
itorWindow
in
Assets\Scripts\Editor
, as follows:
using UnityEditor;
using UnityEngine;
public class MyEditorWindow : EditorWindow
{
String windowName = "My Editor Window";
bool groupEnabled;
bool DisplayToggle = true;
float Offset = 1.23f;
}
I've added some properties to give some depth to the example.
With your new window in place, you then need to implement a function to display the
window when it is called inside the new
MyEditorWindow
class:
[MenuItem ("Window/My Window")]
public static void ShowWindow ()