menu | Menu to show. |
rect | Position and size of the parent control. |
triggerEvent | Event summoning context menu. |
Displays dropdown menu as a contextual menu.
using UnityEditor; using UnityEditor.UIElements; using UnityEngine.UIElements; public class ContextMenuWindow : EditorWindow { [MenuItem("My/Window")] static void ShowWindow() => GetWindow<ContextMenuWindow>(); private void CreateGUI() { Button myContextMenuButton = null; myContextMenuButton = new Button(() => { var menu = new DropdownMenu(); menu.AppendAction("My Action 1", null, DropdownMenuAction.AlwaysEnabled); menu.AppendAction("My Action 2", null, DropdownMenuAction.AlwaysEnabled); menu.AppendAction("My Action 3", null, DropdownMenuAction.AlwaysEnabled); EditorMenuExtensions.DisplayEditorMenu(menu, myContextMenuButton.worldBound); }); myContextMenuButton.text = "My Contex Menu Button"; } }