Version: 2023.2
LanguageEnglish
  • C#

EditorMenuExtensions.DisplayEditorMenu

Suggest a change

Success!

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.

Close

Submission failed

For 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.

Close

Cancel

Declaration

public static void DisplayEditorMenu(UIElements.DropdownMenu menu, Rect rect);

Declaration

public static void DisplayEditorMenu(UIElements.DropdownMenu menu, UIElements.EventBase triggerEvent);

Parameters

menu Menu to show.
rect Position and size of the parent control.
triggerEvent Event summoning context menu.

Description

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";
    }
}