Hello UI Toolkit experts,
at the moment I am trying to create some sort of radial menu for my game. It will work like this:
The user holds the mouse button, the menu appears. He hovers over a menu option - it is being selected by evaluating the mouse position relative to the center of the menu. When the user lets go of the mouse button, the selected option is being confirmed and the menu is hidden again.
The steps:
- The game detects that the user has long-pressed somewhere within a behavior.
- The behavior gets disabled, the UI, just 5 plain visual elements at the moment, is made visible.
- While the user still holds down the mouse button, the mouse is captured by the radial menu.
- The mouse-move-events are generated and are being captured properly by the radial menu.
- When releasing the mouse, no mouse-up-event is being received. I have to press the button again and release it to make it count. The pointer up event is only being generated when there is a pointer down event before.
Is this a bug? How can I make the event system aware of the fact that there has been a pointer down event sometime before?
BR,
Andrej
PS: Maybe some code might help:
This is called when the behavior detects the long press:
public void ShowContextMenu(int mouseButton)
{
radialContextMenu.Show(defaultInputHandler.activeCamera, mouseButton);
enabled = false;
}
This is how the mouse is captured by the UI:
public void Show(ACam activeCamera, int mouseButton)
{
this.mouseButton = mouseButton;
center.CaptureMouse();
center.style.display = DisplayStyle.Flex;
}
And this is the method that is called when the mouse-up-event is received:
private void ConfirmSelection(MouseUpEvent e)
{
if(e.button != mouseButton) return;
center.ReleaseMouse();
center.style.display = DisplayStyle.None;
inputStateMachine.OnContextMenuOptionChosen();
Debug.Log("option chosen!");
}
This is where my non-ui input handling is reactivated:
public void OnContextMenuOptionChosen()
{
enabled = true;
currentState = defaultInputHandler;
}