Author Topic: UIKeyBinding and OnSelect() Callback  (Read 2546 times)

docgonzzo

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 10
    • View Profile
UIKeyBinding and OnSelect() Callback
« 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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIKeyBinding and OnSelect() Callback
« Reply #1 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.

docgonzzo

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: UIKeyBinding and OnSelect() Callback
« Reply #2 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.