Context Menu

To use the menu, you need to add a ContextMenu component and ContextMenu template. Different menus can use the same template.
Menu items are edited in a separate window which can be opened from the ContextMenu component.
In this window, you can specify menu items: name, icon, checkmark, item template, hotkey, and action when the item is clicked.
Initially, two item templates are available: the default template and the delimiter template; a minus sign is used as the key of the delimiter.
Any string can be used as a template key, not just signs.
The keyboard is supported: you can open the menu and navigate between menu items.
Hotkeys work out of the box with both legacy input and a new input system.

Options

  • Interactable bool

    Allow users interact with the ListView.

  • Template ContextMenuTemplate

    Context menu template.

  • MenuItems ObservableList<MenuItem>

    Menu items.

  • Is Default bool

    Is default menu? Default menu will be opened on context menu key press.

  • Navigation bool

    Enable keyboard and gamepad navigation.

  • Open On Right Button Click bool

    Open context menu on right mouse button click.

  • Open On Context Menu Key bool

    Open context menu on context menu key press.

  • Submenu Delay float

    Delay before open and close sub menu.

  • Unscaled Time bool

    Use unscaled time.

Events

  • OnOpen UnityEvent<ContextMenu>

    The event raised when context menu opened.

    Arguments: opened context menu.

  • OnClose UnityEvent<ContextMenu>

    The event raised when context menu closed.

    Arguments: closed context menu.

  • OnItemSelect UnityEvent<MenuItem>

    The event raised when menu item selected.

    Arguments: selected menu item.

  • OnItemDeselect UnityEvent<ContextMenu>

    The event raised when menu item deselected.

    Arguments: selected menu item.

ContextMenu for non-UI Gameobjects

You can add the OpenContextMenu component with the ContextMenu reference to a non-UI game object and the menu will be opened on the right mouse button click.
Or you can open the menu with the script:
contextMenu.Open(eventData);