Game Development Reference
In-Depth Information
{
EditorWindow.GetWindow(typeof(MyEditorWindow));
}
It doesn't matter what the preceding function is called; it's just an editor reference attribute
attached to the function that shows where the option will appear in the Unity editor menu.
If you want more control over the size and position of your editor window, instead of us-
ing the preceding GetWindow function, you can use the following GetWin-
dowWithRect function:
[MenuItem ("Window/My Window")]
public static void ShowWindow ()
{
EditorWindow.GetWindowWithRect(typeof(MyEditorWindow),
new Rect(0, 0, 400, 150));
}
This will set the position and size of the window to a fixed point on the screen, but as with
all other editor windows, it can then be resized and docked like any other window. This
method is more useful to display a collection of properties in the scene view to edit nodes
or other position-based visual configuration.
Lastly, you need some GUI code. This is pretty much the same as the normal GUI code,
but with a few editor extensions because it is being drawn in the editor. This goes in to an
OnGUI method, for example:
void OnGUI()
{
// Your custom Editor Window GUI code
GUILayout.Label("Base Settings",
EditorStyles.boldLabel);
windowName = EditorGUILayout.TextField("Window Name",
windowName);
groupEnabled =
EditorGUILayout.BeginToggleGroup("Optional Settings",
groupEnabled);
Search WWH ::




Custom Search