Extending the Editor
Unity allows you to use your own custom inspectors and editor Windows Extension Editor, and you can use the custom property drawers to define how the attribute set is presented in inspector, a piece that tells you how to use these features.
Editor Windows
You can create any number of custom windows in your app. They behave like inspector,scene or other built-in Windows. This is a great way to add a subsystem user interface to your game. [e.g. Map editor]
Making a custom editor window contains the following simple steps:
1. Create scripts to inherit the Editorwindow class
2. Use the code to trigger the window to display itself
3. Implement GUI code for your tools
Derive from Editorwindow
In order to make your editor window, your script must be stored in a folder called "Editor". Create a class in this script that inherits from Editorwindow. Then write your GUI control inside the Ongui method.
using Unityengine; using Unityeditor; using System.Collections; Public class example:editorwindow{ void Ongui () { // the actual Window code goes here }}
Showing the window
In order to display the window on the screen, make a menu item to display it, this is done by creating a method, and activating this method depends on the MenuItem property.
The default behavior of unity is to recycle the window (that is, select menu item again to display a window that already exists.) This is accomplished by using the Editorwindow.getwindow method), for example:
usingUnityengine;usingUnityeditor;usingSystem.Collections;classMywindow:editorwindow {[MenuItem ("window/my Window")] Public Static voidShowWindow () {Editorwindow.getwindow (typeof(Mywindow)); } voidOngui () {//The actual window code goes here }}
This creates a standard, dockable editing window that saves its location between instructions, can use a custom layout, and so on. To get more control, you can use Getwindowwithrect.
Implementing Your Window ' s GUI
The actual contents of the window are drawn by implementing the Ongui method. The Unitygui classes (GUI and guilayout) that you use in the in-game GUI are also available here. In addition we provide some additional GUI operations, which are inside the Editor-only class: Editorgui and Editorguilayout. These classes are added to the collection of controls that are already available in the normal class, so you can mix and match them as you like.
The following C # code shows how you can add GUI elements to your custom Editorwindow:
usingUnityeditor;usingUnityengine; Public classmywindow:editorwindow{stringMyString ="Hello World"; BOOLgroupenabled; BOOLMybool =true; floatMyfloat =1.23f; //Add menu item named "My window" to the Window menu[MenuItem ("window/my Window")] Public Static voidShowWindow () {//Show Existing window instance. If one doesn ' t exist, make one.Editorwindow.getwindow (typeof(Mywindow)); } voidOngui () {Guilayout.label ("Base Settings", Editorstyles.boldlabel); MyString= Editorguilayout.textfield ("Text Field", myString); Groupenabled= Editorguilayout.begintogglegroup ("Optional Settings", groupenabled); Mybool= Editorguilayout.toggle ("Toggle", Mybool); Myfloat= Editorguilayout.slider ("Slider", Myfloat,-3,3); Editorguilayout.endtogglegroup (); }}
Sample code execution results such as:
For more information, take a look at the samples and documentation on the Editorwindow page
Unity Extension Editor 1:editor Windows