Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Closemenu | 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"; } }