Author Topic: NGUI setting UICamera.selectedObject to null?  (Read 5009 times)

eucryptic

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
NGUI setting UICamera.selectedObject to null?
« on: May 17, 2013, 02:06:28 AM »
I'm trying to use UIButtonKeys and NGUI, and having weird results still.

Looking through the code, it seems that NGUI calls ProcessTouch after calling ProcessOther, so after pressing Enter on a button to change menus, suddenly UICamera.selectedObject gets set to null, removing the focus.

  1. UICamera:set_selectedObject(GameObject) (at Assets/NGUI/Scripts/UI/UICamera.cs:351)
  2. UICamera:ProcessTouch(Boolean, Boolean) (at Assets/NGUI/Scripts/UI/UICamera.cs:1062)
  3. UICamera:ProcessOthers() (at Assets/NGUI/Scripts/UI/UICamera.cs:995)
  4. UICamera:Update() (at Assets/NGUI/Scripts/UI/UICamera.cs:795)

Why would it be doing this?

It seems to change depending on whether the UIButton that calls my script has a trigger of OnPress or OnClick.
When it's OnClick() only one event is generated when you let go of the key, but with OnPress() it seems to generate a bunch of weird touch events that cause UICamera.selectedObject to be set to null.
« Last Edit: May 17, 2013, 02:12:03 AM by eucryptic »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI setting UICamera.selectedObject to null?
« Reply #1 on: May 17, 2013, 02:33:10 AM »
If you're using UIButtonKeys, then you should disable touch and mouse input on the UICamera.

eucryptic

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: NGUI setting UICamera.selectedObject to null?
« Reply #2 on: May 17, 2013, 02:39:57 AM »
The device we're targetting has both controller like buttons and touch input, so unfortunately that's not an option. We need to support being able to navigate via touch and via a controller.

It seems that if I set UIMessage to onPress, the message is sent correctly, but then when I let go of the button, another message is sent which messes up the current selection.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI setting UICamera.selectedObject to null?
« Reply #3 on: May 17, 2013, 03:52:24 AM »
Well, only one type of input can work at a time. You can't have a selection-based input work with mouse-based input properly because in a selection-based input you should never be able to have selectedObject be null, but with a mouse it's perfectly fine.

You'll need to write your own logic for this.

KeithT

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: NGUI setting UICamera.selectedObject to null?
« Reply #4 on: May 17, 2013, 11:25:10 AM »
We are having problems with this as well using UIButtonKeys and trying to make the NGUI menu work with the keyboard and the mouse e.g. on a PC.

It seems that once UICamera.selectedObject has gone null, which happens whenever anyone clicks a mouse, then it's game over, the last item that was selected using the keyboard is selected forever. Is there anyway to re-initialise this ? Have tried turning inputs on and off but can't get the selected object to deselect.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI setting UICamera.selectedObject to null?
« Reply #5 on: May 18, 2013, 05:58:08 AM »
This is precisely why in the upcoming UI system I've chosen to completely separate controller-based input from mouse and touch. You can either have a Touch Button, or a Controller Button. Not both. ;)

Bottom line is, as I said -- don't mix the two. Either you control with a controller, or with a mouse/touch. If you want both, you will need to write your own custom logic that makes sure that selectedObject can't be null.

wizardsmoke

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 5
  • Posts: 40
    • View Profile
Re: NGUI setting UICamera.selectedObject to null?
« Reply #6 on: May 18, 2013, 10:54:53 AM »
Maybe you could dynamically switch between the two input methods by detecting which is being currently used.  For instance, whenever the mouse moves switch to mouse input, and whenever a key is pressed on the keyboard, switch to keyboard input.

KeithT

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: NGUI setting UICamera.selectedObject to null?
« Reply #7 on: May 20, 2013, 03:10:36 AM »
Explaining to clients that they can only use the keyboard OR the mouse on their PC is not a conversation I relish, so we have implemented external logic which manages UICam.selectedobject and so works with both.

It took hours of debugging mind, working out when selectedobject it is changed internally within UICam class, which I think is what makes it so difficult to understand why it does not work when monitoring and setting the public variable externally.

Now we need to come up with a work around to handle the same issue for the change selected object handler in popuplists so that that works with both.

For the billion or so PCs our clients target, the only use one at once approach is not credible.