Author Topic: UIButtonKeys not working on Android?  (Read 5105 times)

Dreamzle

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
UIButtonKeys not working on Android?
« on: October 22, 2012, 03:07:01 PM »
I just bought NGUI, and immediately made a simple 3-button menu using UIButtonKeys so the menu could be controlled with joystick.  And it works perfectly in the Unity Editor.  But when I burn the game to my Android device, the joystick doesn't work with the menu (it does work elsewhere in the game).  The menu doesn't even start with the top button selected, though "Starts Selected" is checked for that button.

Any ideas?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButtonKeys not working on Android?
« Reply #1 on: October 22, 2012, 05:14:34 PM »
Keyboard and mouse events are forcefully-disabled on mobile devices. I'm not sure how what you're making is supposed to work. UIButtonKeys suggests keyboard or joystick requirement... but you are targeting an android device, so how can it possibly have either?

Dreamzle

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIButtonKeys not working on Android?
« Reply #2 on: October 22, 2012, 07:00:25 PM »
Android added joystick support in I think 4.0 (and it's got USB and bluetooth keyboard drivers as well), there are a number of games supporting gamepad these days, including big ones like Sonic 4.  Unity treats the analogue sticks exactly the same in Android as anything else.  My game is currently entirely joystick driven, and it works great on my Asus Transformer Prime TF700 with a PS3 controller.  I'm eventually going to be targeting the Ouya game console, which runs on Android but doesn't have a touchscreen.
« Last Edit: October 22, 2012, 07:02:26 PM by Dreamzle »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButtonKeys not working on Android?
« Reply #3 on: October 22, 2012, 08:04:50 PM »
Orly... news to me, and I even have a Transformer Infinity pad.

Well, open up UICamera, and edit out this part as you see fit:
  1. if (Application.platform == RuntimePlatform.Android ||
  2.         Application.platform == RuntimePlatform.IPhonePlayer)
  3. {
  4.         useMouse = false;
  5.         useTouch = true;
  6.         useKeyboard = false;
  7.         useController = false;
  8. }

Dreamzle

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIButtonKeys not working on Android?
« Reply #4 on: October 22, 2012, 11:33:00 PM »
Thanks, I actually found that myself first, after you said you had forced the controls disabled on mobile devices.  I removed the Android check there, and switched the submitkeys over to the buttons that the PS3 controller uses (Joystick1Button14 and Joystick1Button13 for X and O) and it worked great!  I now have a full joystick-controlled menu running in my game on Android.