Version: 2023.2
public bool allowSubmenus ;

描述

Allows the creation of submenu items.

Submenus are separated from action items by a '/' delimiter. Submenus can stack on top of each other to create deep submenus.

using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

public class ContextMenuWindow : EditorWindow { [MenuItem("My/Context Menu Window")] static void ShowMe() => GetWindow<ContextMenuWindow>();

void CreateGUI() { var contextMenuContainer = new VisualElement(); contextMenuContainer.style.flexGrow = 1; contextMenuContainer.AddManipulator(new ContextualMenuManipulator(e => { e.menu.SetDescriptor(new DropdownMenuDescriptor() { allowSubmenus = true, });

e.menu.AppendAction("Submenu/Action 1", a => Debug.Log("Action 1 Works"), DropdownMenuAction.AlwaysEnabled); }));

rootVisualElement.Add(contextMenuContainer); } }