Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: docgonzzo on July 20, 2015, 07:56:58 PM

Title: UIKeyBinding and OnSelect() Callback
Post by: docgonzzo on July 20, 2015, 07:56:58 PM
Hi Again!

I'm trying to use UIKeyBinding to assign keyboard buttons to hot-bar buttons.

I have everything working properly, however it seems that when I use UIKeyBinding to "Press And Click" a button, another button that is currently "Selected" does not execute its OnSelect(false) callback.

The OnSelect(false) callback executes properly when another button is clicked with the mouse, but not through the UIKeyBinding.

Any hints on why this is occuring?
Title: Re: UIKeyBinding and OnSelect() Callback
Post by: ArenMook on July 21, 2015, 11:47:16 AM
Key binding doesn't select anything for press and click events. Check the code for it. If you want it to be selected as well, just do it in the function called from the press callback.
Title: Re: UIKeyBinding and OnSelect() Callback
Post by: docgonzzo on July 21, 2015, 05:51:25 PM
Thanks for the tip.

In the end I have solved this by manually assigning UICamera.hoveredObject and UICamera.selectedObject in the OnClick() callback for my buttons. The UIKeyBinding is set to "Press and Click" so that OnClick executes when the bound keyboard key is pressed.

So now the bound keyboard key press behaves just like a mouse click.

  1. void OnClick()
  2. {
  3.    UICamera.hoveredObject = gameObject;
  4.    UICamera.selectedObject = gameObject;
  5.  
  6.    //remaining code
  7. }
  8.