Author Topic: Upgraded NGUI to 3.9.0b, controller scheme broken disregarding the submit config  (Read 5178 times)

Sundaerae

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 9
    • View Profile
I had set the submit 1 to Z, for debugging using keyboard, and submit 2 to Joystick Button 1 (red B on XBox controller, wanted to do japanese style input), and I'm gonna change those submit button based on user input.
Somehow after upgrading none of these buttons work. UIButton widget, UIEventTrigger, none of them OnClick worked.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
What did you use this submit for? NGUI 3.9.0+ sends all key events now, not just a select few.

Sundaerae

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 9
    • View Profile
For 'clicking' anything on NGUI. I can't even click anything now.
I see in your UICamera that you hardcoded it to joystick button 0, which isn't what I want, since different gamepad have different button scheme, and also I use custom input so player can customize their own buttons.
In the previous version I use (3.8.0) I can do this easily by changing the submit0 & submit1 keycode to the keycode I want. I can't now.
Also the new context switching becomes a problem if I want to make a console-like games, use keyboard & controller only without mouse, since now, enabling keyboard also enabling mouse, which intervenes with the events (mouse accidentally hovers, etc)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Nothing is hard-coded. Where are you seeing this? You can change the submit keys by selecting the UICamera component. Furthermore you can set UICamera.Get series of functions like GetButtonDown via code to custom functions instead. I did that to get InControl plugin integration for Windward for example. InControl handles all kinds of joysticks and controllers for you, so you don't need to keep track of different key binds yourself. I suggest you have a look at it: http://www.tasharen.com/forum/index.php?topic=13047.0

Sundaerae

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 9
    • View Profile
in UICamera
  1. static public ControlScheme currentScheme
  2.         {
  3.                 get
  4.                 {
  5.                         if (mCurrentKey == KeyCode.None) return ControlScheme.Touch;
  6.                         if (mCurrentKey >= KeyCode.JoystickButton0) return ControlScheme.Controller;
  7.                         return ControlScheme.Mouse;
  8.                 }
  9.                 set
  10.                 {
  11.                         if (value == ControlScheme.Mouse)
  12.                         {
  13.                                 currentKey = KeyCode.Mouse0;
  14.                         }
  15.                         else if (value == ControlScheme.Controller)
  16.                         {
  17.                                 currentKey = KeyCode.JoystickButton0;
  18.                         }
  19.                         else if (value == ControlScheme.Touch)
  20.                         {
  21.                                 currentKey = KeyCode.None;
  22.                         }
  23.                         else currentKey = KeyCode.Alpha0;
  24.                 }
  25.         }
  26.  
those lines changes the current key to KeyCode.JoystickButton0; which disregading the submitKey1 that I set to JoystickButton1, while making pressing the keyboard (which I set submitKey0 to 'Z' button on keyboard) change the scheme to Mouse, which would make these lines
  1. if ((submitKeyDown || submitKeyUp) && currentScheme == ControlScheme.Controller)
  2.                 {
  3.                         currentTouch.current = controllerNavigationObject;
  4.                         ProcessTouch(submitKeyDown, submitKeyUp);
  5.                         currentTouch.last = currentTouch.current;
  6.                 }
  7.  
Won't be processed since the scheme is Mouse

This is just my conjecture, so forgive me if those lines don't actually do something like I thought it would. I still can't use 3.9.0b the right way, it just won't do things that worked on 3.8.0.
Another example: 3.8.0 use Select/Deselect as the triggered event when a widget is selected from controller (I'm using UIEventTrigger component), whereas 3.9.0b use HoverOver/HoverOut. Switching to hover is not a big problem, but sometimes the HoverOut didn't trigger, making some function that was supposed to be called, not called.
« Last Edit: July 31, 2015, 04:16:38 AM by Sundaerae »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
When UICamera.currentScheme is set, it changes the scheme by setting the "currentKey" property. JosytickButton0 in that case does nothing except switches the control scheme. I'm not sure why it's causing any issues for you. What's the call stack of it being called?

Sundaerae

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 9
    • View Profile
I'm not sure either, since I already revert to using 3.8.0 so I can't really test.
But last time I tested, NGUI only accept joystick button0 as input, whatever joystick button I put as submitKey1 or submitKey2. Whatever I put in UICamera inspector is ignored.
And scheme changing problem (the 1st, combined by 2nd code lines I posted before) also ignore submitKey1 & submitKey2 if I put keyboard button in them.

The way to replicate them is easy, make UI, set enabled scheme to controller only (or controller & keyboard, I don't think these options even used anymore), disabling touch and mouse, set submitKey1 to Z, submitKey2 to joystick button1; or, whatever input that is 'not' return and joystick button0. Try using those buttons.
In my case (new empty project, only has NGUI 3.9.0b, new scene with 2 button and UIKeyNavigation), those submit buttons don't work. But, if you try pressing joystick button0, the onClick triggered. This is why I think your input procedsing is hardcoded to joystick button0.
« Last Edit: August 01, 2015, 01:16:38 PM by Sundaerae »