Unity Editor Extensions –menu Items

Source: Internet
Author: User

Reference: Https://unity3d.com/cn/learn/tutorials/topics/interface-essentials/unity-editor-extensions-menu-items

  

The Unity MenuItem property class allows you to extend the main menu, the property Bar content menu, the hierarchy Bar menu, and the Resource bar menu.

MenuItem can convert any static function to a menu command, only the static function can use the MenuItem property.

Add menu Options

Add a Simple Main menu button

using Unityeditor; using Unityengine;
public class MenuItems{    [MenuItem("Tools/Clear PlayerPrefs")]    private static void NewMenuOption() { PlayerPrefs.DeleteAll(); }}

shortcut Keys

The following modifier keys and special keys (which can be used in conjunction) are supported:

    • %–ctrl on Windows/cmd on OSX
    • #–shift
    • &–alt
    • Left/right/up/down–arrow keys
    • F1 ... f2–f keys
    • HOME, END, PgUp, PGDN

If you do not use a modifier key, you need to add an underscore before the shortcut key, such as: _g for shortcut G, shortcut text must be preceded by a space, otherwise the shortcut key does not work.

//Add a new menu item with hotkey ctrl-shift-a[MenuItem ("tools/new Option% #a")]Private Static voidnewmenuoption () {}//Add a new menu item with hotkey Ctrl-g[MenuItem ("Tools/item%g")]Private Static voidnewnestedoption () {}//Add a new menu item with hotkey G[MenuItem ("tools/item2 _g")]Private Static voidNewoptionwithhotkey () {}

Special Paths

Some special paths are added to the right-click menu:

Assets-items is added to the Assets menu bar and is added to the right-click menu of the Resource bar.

The Assets/create-items is added to the resource bar "create" button popup and the right-click menu in the Create item.

Context/componentname–items will be added to the corresponding component in the property bar right-click menu.

//Add a new menu item accessed by right-clicking on a asset in the project view[MenuItem ("assets/load Additive Scene")]Private Static voidLoadadditivescene () {varSelected =Selection.activeobject; Editorapplication.opensceneadditive (Assetdatabase.getassetpath (selected));} //Adding a new menu item under Assets/create[MenuItem ("Assets/create/add Configuration")]Private Static voidAddconfig () {//Create and add a new scriptableobject for storing configuration} //Add A new menu item that's accessed by right-clicking inside the Rigidbody component[MenuItem ("context/rigidbody/new Option")]Private Static voidnewopenforrigidbody () {}

Resource Bar Right-click menu

Resource Bar Create button Bounce window

Component Right-click menu

Unity Editor Extensions –menu Items

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.