Unity Plugin Development--menuitem

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.