The lack of some centralized info about how to get your Unity game running on the Ouya with controller support has lead me to write this post. I spent a lot of time reading over at the ouya dev site, ouya forums, github, social networks, blogs… and I finally got it working!
Getting the OUYA-Unity plugin ready:
- Grab the source from github.
- Open Unity and tell it to open the project you’ve just downloaded in step 1.
- Click on “OUYA > Export Core Package“.
- Open your game project and click on “Assets > Import Package > Custom Package“. Import all content. Beware that this package includes an “Input Manager.asset” which will overwrite all your custom input you may have in “Edit >Project Settings > Input“. Since there is no “merge” that I know of, I just took a couple screenshots of my current input manager, imported the ouya one, and then added back the custom controls I had before using the screenshots as reference.
- Click on “Window > Open OUYA Panel“. The first thing you’ll probably notice is a warning: ”[error] Bundle mismatched”. Write your desired bundle ID and click on “Sync Bundle ID“. Error should be gone.
- There are several tabs at the top. Go check them all, if you find something grayed out it means that it’s missing so you’ll need to download the according library (or just select its path if you have it already).
- Update Android SDK to API 16 using the Android SDK Manager. Android SDK Tools should be rev.21, do not update it to rev.22.
- Android NDK path should not contain any spaces (otherwise it will throw an error). Also, version r8d needs a fix in the file ndk/build/gmsl/__gmsl - Open it with a text editor and replace line 512 with the following:
int_encode = $(__gmsl_tr1)$(wordlist 1,$(words $1),$(__gmsl_input_int))
- Click on “Compile” (in Ouya Panel). The ODK is now ready to be used.
- Drag & drop “OuyaGameObject” prefab from the imported Prefabs folder into your initial scene. This object will be persistant across all your levels so it should be in a scene previous to your main menu, so it gets loaded just 1 time.
- Grab your developer ID from here and put it in the available slot in “OuyaGameObject” prefab in your scene.
- Remember to publish your .apk targeting API 16 or above!
Getting the OUYA recognized as an Android device under Windows 7:
- Connect your OUYA via USB to your computer. You’ll be able to access the device as a media device but one driver will fail so the device will not be seen by Unity / adb. Let’s fix that.
- Open the root folder of your Android SDK and navigate to “extras/google/usb_driver/android_winusb.inf”. Open it with a text editor and add the following text under both the [Google.NTx86] and the [Google.NTamd64] sections:
;OUYA Console %SingleAdbInterface% = USB_Install, USB\VID_2836&PID_0010 %CompositeAdbInterface% = USB_Install, USB\VID_2836&PID_0010&MI_01
- Go to your Windows Device Manager. Right click on the OUYA > “Update driver” > “Browse my computer” > “Pick from a list” > “Have disk” > Now go select the file you edited in step 2, and install it as “Android composite ADB Interface“.
- OUYA device is ready!
Getting the controller to work:
- Download “SuperInputMapper.cs” by Sophie Houlden (and say thanks to her! @S0phieH) and put it in your project. If you are using UnityScript, this needs to go in the “Plugins” folder.
- You can query button presses like this:
if(SuperInputMapper.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_RIGHT, OuyaSDK.OuyaPlayer.player1)) moveRight();
And query axis like this:
axisValue = SuperInputMapper.GetAxis(OuyaSDK.KeyEnum.AXIS_LSTICK_X, OuyaSDK.OuyaPlayer.player1);
- Quick reference of button names:
OuyaSDK.KeyEnum.BUTTON_O OuyaSDK.KeyEnum.BUTTON_U OuyaSDK.KeyEnum.KEYCODE_BUTTON_Y OuyaSDK.KeyEnum.BUTTON_A OuyaSDK.KeyEnum.BUTTON_LB OuyaSDK.KeyEnum.KEYCODE_BUTTON_L2 OuyaSDK.KeyEnum.BUTTON_RB OuyaSDK.KeyEnum.BUTTON_RT OuyaSDK.KeyEnum.BUTTON_L3 OuyaSDK.KeyEnum.BUTTON_R3 OuyaSDK.KeyEnum.BUTTON_SYSTEM OuyaSDK.KeyEnum.AXIS_LSTICK_X OuyaSDK.KeyEnum.AXIS_LSTICK_Y OuyaSDK.KeyEnum.AXIS_RSTICK_X OuyaSDK.KeyEnum.AXIS_RSTICK_Y OuyaSDK.KeyEnum.BUTTON_DPAD_UP OuyaSDK.KeyEnum.BUTTON_DPAD_RIGHT OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN OuyaSDK.KeyEnum.BUTTON_DPAD_LEFT
Getting the controller to work… with NGUI’s uibuttonkeys:
- Update NGUI to the latest version so you don’t need to hack into uicamera.cs (this was needed before the update).
- UICamera.onCustomInput will allow you to pass a custom function that will be processed by NGUI with the rest of the input (keyboard, touch…). You just need to write this:
UICamera.current.onCustomInput = yourFunction;
And then create a function that processes OUYA Input and passes it to NGUI using UICamera.Notify. Here it’s the complete script I’m using, if it’s of any help.
This is it. I tried to keep this guide extra-concise so you can quickly get a grasp of what’s going on. If you struggle at some point, you can check any of the following links since they are the main source where I’ve gathered all this data:
P.S.: There is a new Controller Framework being developed, I haven’t looked at it yet but here it is if you want to give it a try.