I’ve been unable to get context menus to show up. Here’s my code:
using UnityEngine;
using UnityEngine.UIElements;
public class Test : MonoBehaviour
{
private UIDocument _uiDocument;
private VisualElement _redSquare;
private void OnEnable()
{
_uiDocument = GetComponent<UIDocument>();
_redSquare = _uiDocument.rootVisualElement.Q<VisualElement>(name: "test");
_redSquare.focusable = true;
_redSquare.pickingMode = PickingMode.Position;
_redSquare.AddManipulator(new ContextualMenuManipulator(HandleContextMenuEvent));
}
private void HandleContextMenuEvent(ContextualMenuPopulateEvent contextMenuEvent)
{
contextMenuEvent.menu.AppendAction($"TESTING", HandleTestingClick, DropdownMenuAction.AlwaysEnabled);
}
private void HandleTestingClick(DropdownMenuAction dropdownMenuAction)
{
Debug.Log("TEST");
}
}