Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: jcbadboy on November 07, 2015, 04:55:18 PM

Title: hoveredObject + selectedObject + controllerNavigationObject (v3.9.4b)
Post by: jcbadboy on November 07, 2015, 04:55:18 PM
Hi Guys!

I´m working on a project using joystick plus mouse/keyboard on screens navigations. I know NGUI is not designed to word simultaneously with this devices, but:
Our screens have a lot of transitions, screens overlaping each other, animations, and button states (over, pressed). And, need to work simultaneously with both devices (joystick + mouse/keyboard).

Do this thing have been very tricky.

My problem number 1:
Some times simply set programmatically the hoveredObject and controllerNavigationObject does not work, and ngui loses focus. So, i have been trying to wait a frame or wait tweens until it finishes, to set the focus of the navigation on screen. Sometimes i even set selectedobject to be sure it works.

My problem number 2:
Obviously, before all of this, sometimes ngui loses focus.
On update 3.9.0 i remember of this:
- NEW: NGUI now automatically finds and focuses on an appropriate UIKeyNavigation object if none has focus while receiving controller-based input.
I think this "automatically way of find and focuses" can be disturbing my "precise control of focus".

So, i ask:
There is a best practice for work on hoveredObject and controllerNavigationObject on NGUI?
I´m trying to precisely control focus between screens on my project. Is that right?
What i´m doing wrong when a set controllerNavigationObject  and hoveredObject?

Some times i try to save localy the reference of UICamera.controllerNavigationObject. So, when I come back to the last screen, I set it back and keep my navigation on. But, half the time the reference is not exactly what i was expecting. And navigation breaks. I know UICamera has your own update and inside a frame is a lot of things happening. Is that the right way to do this or i need to not trust on UICamera state? (or) Is a better approach make each screen save your proper focus independently?

Thank you in advenced.
Title: Re: hoveredObject + selectedObject + controllerNavigationObject (v3.9.4b)
Post by: diederik on November 09, 2015, 04:07:24 AM
Hi!

You might want to check this post I made some time ago:
http://www.tasharen.com/forum/index.php?topic=13348.msg60017#msg60017
I was experiencing similar issues.
I think the solution was to disable the mouse input events on the UI camera, when the player is not explicitely using the mouse.
The mouse picking functionality was messing up the keyboard / joystick selection.
This hopefully would improve your code that manually sets the selected object.

Good luck!

Diederik / Xform
Title: Re: hoveredObject + selectedObject + controllerNavigationObject (v3.9.4b)
Post by: ArenMook on November 10, 2015, 08:22:34 PM
NGUI will switch to controller-based navigation if you use a controller/joystick bound to the axes specified on the UICamera (Navigate and Pan axes). You can turn this off by unchecking the "Controller" checkbox on the UICamera, or clearing the Navigate fields on the UICamera.

You can turn off NGUI's hiding of the mouse when it switches to controller input using the "Auto Hide Cursor" checkbox on the UICamera.

You likely should not be setting the hovered object at all -- that's for NGUI to set. You can set the UICamera.controllerNavigationObject however. That said, UIKeyBinding does set the hovered object, but it's done only to show highlighting of a button when a key is pressed.

Don't use the UICamera.hoveredObject as your "focused object" btw -- use the controllerNavigationObject or selectedObject instead.
Title: Re: hoveredObject + selectedObject + controllerNavigationObject (v3.9.4b)
Post by: jcbadboy on November 11, 2015, 11:35:21 AM
Thank you guys!
I will try some changes following your steps.
I will keep you informed.
Title: Re: hoveredObject + selectedObject + controllerNavigationObject (v3.9.4b)
Post by: jcbadboy on November 20, 2015, 03:51:17 PM
Well Guys, i am now on that days....this line of code simply does note work:

UICamera.controllerNavigationObject = go;
UICamera.selectedObject = go;

The case here is, i have this pop-up dialog screen above all other screen.
Before this happen, navigationobject (as selectedobject) was a "play button".
So, pop up shows and would switch navigationobject (and selectedobject) to "ok button".
But is not working. I dont know if ngui is taking your decisions here and changing the reference I already set.

I am trying to wait a frame using coroutines. But it works 50% of the time.

 I´m in trouble here. Sure I am not understanding half this the scenarios. But, seriously, I think ngui must to solve better stuff like this.
Title: Re: hoveredObject + selectedObject + controllerNavigationObject (v3.9.4b)
Post by: diederik on November 24, 2015, 09:53:44 AM
Hi!

What you want to do there is quite tricky, and I would definitely not attempt it if you want to have keyboard controls for the buttons as well.
In my project I also have a dialog panels that pops up, but I (wisely) deactivate the whole underlying panel FIRST and switch it back on when I'm done with the dialog.
This way I can never select buttons I don't want to, at the cost of not seeing anything underneath the dialog.
But it kind of provides the dialog with more 'user attention' when the rest is hidden.
(alternatively you could maybe put all the UIButtons of the underlaying panel in a list en deactivate them somehow).
A further advantage is that NGUI has no chance to select any weird buttons I don't want it to.

Hope this helps. Kind of.

Diederik
Title: Re: hoveredObject + selectedObject + controllerNavigationObject (v3.9.4b)
Post by: ArenMook on November 25, 2015, 05:48:34 PM
The controller / selection object setting won't work if the object is disabled. You need to make sure it's enabled first before setting it.