Author Topic: UIKeyNavigation - Double tapping a direction deselects the current button  (Read 413 times)

Lork

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
If mouse events are enabled, quickly double tapping a direction will deselect the current button.  This is not just a visual glitch, as the submit button won't do anything in this state.  The position is still remembered though as you can recover by pressing a direction again to select an adjacent button.  It's easiest to see this in menus that only let you move on one axis (eg. double tapping left or right on a vertical menu) but it still happens even if the direction you're tapping is changing selections at the same time.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,137
  • Toronto, Canada
    • View Profile
When you have key navigation, you should ideally turn off other forms of input. If you engage another form of input, such as touch or mouse, that effectively hides the key-based navigation. It's the expected behaviour.

Lork

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
The issue isn't caused by engaging other forms of input.  The current button is deselected when a directional button on the keyboard is quickly pressed twice.  Surely it's not expected behavior for keyboard input to hide key based navigation?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,137
  • Toronto, Canada
    • View Profile
I'm not seeing that behaviour here. Perhaps check your Input Manager settings in Unity? Do you have some joystick axis bound to arrow keys?

Lork

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
To reproduce:

-Start a new project, import NGUI and set up the Pan axes.
-Open the controller input example scene.
-Check the keyboard box on UICamera (so that keyboard, mouse and controller are checked)
-Double tap a direction OR press any button on the keyboard that isn't assigned in UICamera's axes and keys.

While setting up this test I learned that the problem actually stems from the interaction between keyboard and mouse events.  Controller and mouse events seem to get along just fine.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,137
  • Toronto, Canada
    • View Profile
Looked into it. Seems it's actually a conflict between mouse input and controller input. You can fix it by opening up UICamera, line 2181:
  1. if (!wasPressed)
change to:
  1. if (!wasPressed && posChanged)
The downside of this will be that NGUI won't keep updating the object underneath the mouse unless the mouse actually moves now -- which may or may not be what you want.

Edit: Actually you can resolve the downside above by changing the code right above it:
  1.                 // No need to perform raycasts every frame
  2.                 if (isPressed || posChanged || mNextRaycast < RealTime.time)
  3.                 {
  4.                         mNextRaycast = RealTime.time + 0.02f;
  5.                         Raycast(currentTouch);
  6.  
  7.                         if (mMouse[0].current != currentTouch.current)
  8.                         {
  9.                                 currentKey = KeyCode.Mouse0;
  10.                                 posChanged = true;
  11.                                 for (int i = 0; i < 3; ++i) mMouse[i].current = currentTouch.current;
  12.                         }
  13.                 }
« Last Edit: August 30, 2017, 04:52:54 PM by ArenMook »