There is a menu bar in unity where we often use it, such as:
MenuItem's role is to add a menu of his own.
How to use:
In the project assets directory under any editor directory (hereafter referred to as the editor directory, if not, please create a self-created script), such as I created called Menutest. cs, double-click into code editing, create a static function, (code from the official document HTTP ://docs.unity3d.com/documentation/scriptreference/menuitem.html) as follows:
public class Menutest:monobehaviour {
ADD a menu item named "Do Something" to MyMenu in the menu bar. [MenuItem ("Mymenu/do Something")]static void DoSomething () {Debug.Log ("Doing Something ...");
}
}
Save back to unity, compile it and you'll find a mymenu on the menu bar, and a two-level selection menu will appear after clicking Do Something. Click Do Something to output the output window doing Something ...
Yes, the use of MenuItem is as simple as placing the [MenuItem ()] tag on a static function, and inside the brackets is the menu level.
To add, the menu hierarchy can be the hierarchy of the system itself, such as the Window menu, the Assets menu, and so on. For example
public class Menutest:monobehaviour {
ADD a menu item named "Do Something" to MyMenu in the menu bar. [MenuItem ("Mymenu/do Something")]static void DoSomething () {Debug.Log ("Doing Something ...");
}
[MenuItem ("Assets/mymenu")]static void DoSomething () {Debug.Log ("MyMenu click");
}
}
This will generate a MyMenu menu under the system's assets menu.
For the Assets menu, the right-click menu for the Project window. So, use this to create a file right-click menu, such as creating an XML file and so on
OK, this is the basic function of MenuItem, and then advanced usage, such as menu shortcut keys, unavailable state, etc., see official Internet cafes.
Unity Plugin Development--menuitem