Author Topic: Popup list of KeyCodes  (Read 3842 times)

Cizia

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 14
    • View Profile
Popup list of KeyCodes
« on: June 12, 2015, 10:30:30 AM »
Hi,

I would like to make a key mapping screen, I used the UIKeyBiding to make my keys events, which is perfect.

But now I do not know how to show in a popup list a list of KeyCodes, to update my UIKeyBiding with what the user wants.

I tried with UIPopupList and UIScrollView and for now I have no success.

If anyone has a clue, would be much appreciated.

Thanks, and have a good day.

Cizia

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Popup list of KeyCodes
« Reply #1 on: June 12, 2015, 04:16:51 PM »
You can access the key code of a UIKeyBinding like so:
  1. KeyCode key = GetComponent<UIKeyBinding>().keyCode;
What I do in Windward is simple. Right-click a bindable button, and choose the "Rebind" option. This listens to the next key I press, and simply changes UIKeyBinding's keyCode to that value.
  1. void Update ()
  2. {
  3.         for (int i = 0, imax = NGUITools.keys.Length; i < imax; ++i)
  4.         {
  5.                 KeyCode key = NGUITools.keys[i];
  6.  
  7.                 if (UICamera.GetKeyDown(key))
  8.                 {
  9.                         GetComponent<UIKeyBinding>().keyCode = key;
  10.                         return;
  11.                 }
  12.         }
  13. }