Game Development Reference
In-Depth Information
Building your editor menus
Another way of extending in to the editor is to customize it by adding your own menus.
We covered little bits of this in previous chapters by adding extra options to create your
assets and such, but there is much more to it.
Note
MenuItem functions must be declared as Static functions, else they will not be recog-
nized, and scripts must be placed in the special Editor folder.
Adding a MenuItem attribute
The main way of adding a new menu item is to define a script in As-
sets\Scripts\Editor and append the MenuItem attribute to a static method with-
in it. So, create a new script called MyMenu in this folder and replace its contents with the
following code:
using UnityEditor;
using UnityEngine;
public class MyMenu
{
// Add a menu item named MenuItem1 to a Menu option
called
// MenuName in the menu bar.
[MenuItem ("MenuName/MenuItem1")]
static void EnableMyAwesomeFeature ()
{
Debug.Log ("I am a leaf on the wind. Watch how I
soar.");
}
}
This code simply creates a new top-level menu option called MenuName with a single
item called MenuItem1 , as shown here:
Search WWH ::




Custom Search