Parses menu shortcuts at the end of the item name and displays them as keyboard shortcuts next to item names.
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() { parseShortcuts = true, });
e.menu.AppendAction("Action 1 _%F1", a => Debug.Log("Action 1 Works"), DropdownMenuAction.AlwaysEnabled); }));
rootVisualElement.Add(contextMenuContainer); } }