This article is about developing Android games with Gamepad support using Unity and NVIDIA Shield devices. Shield devices run Android and are ideal with developing software for the following reasons:

  • Best in class performance
  • HDMI ouput
  • Long battery life
  • Integrated and best in class Gamepads

When adding Gamepad support to your game, you should also add support for the PC build. This allows rapid development using the PC, rather than having to deploy every small change to the Android device.

What is Unity?

Unity is a popular game engine used by many professional game developers. It is free to download and use which also makes it ideal for students and hobbyists.

Getting Started

Install TADP and ADK

Sign up for NVIDIA's Gameworks Registered Developer Program (it's free) and download the latest version of TADP (The Tegra Android Developer Pack) from our Download Center. This installs all the tools needed, including the latest Android Development Kit.

Install Unity

http://unity3d.com/

Enable USB debugging on your SHIELD

  • Open up the menu Settings -> About SHIELD
  • Find the Build Number. It is the last thing in this menu.
  • Tap the Build Number 7 times to enable USB Debugging
  • Connect you SHIELD to your PC with a USB cable

SHIELD Screen Considerations

Set the project to operate in landscape mode and set the screen resolution to 1280*720. You can also set the Screen.sleepTimeout such that the screen is not dimmed when the application starts up. In reality you are going to have to seriously consider which features you want enabled in your manifest to ensure your game is featured correctly in the store, but this is sufficient to get started.

Check out our Android TV development guide for more information about manifests for Gamepad enabled apps.

Adding Gamepad Support to Unity Applications

By default Unity supports keyboards, mice and joysticks, but to develop for SHIELD and Android micro-consoles Gamepad support is needed. The biggest hurdles are updating Unities Input Manager settings to handle Gamepads and then interpreting the data from the connected Gamepads correctly.

Input Manager

The Input Manager'sjob is to take data from attached input devices and pass it to them to the application. By default the input manager is set up to have input coming from a mouse and keyboard plus a joystick. Gamepads function similarly to joysticks and there may be more than one attached to the system, so the input manager file must be modified. This can be done through the Editor UI (Edit>Project Settings>Input) or by hand editing the InputManager.asset file in the project settings directory. The sample provided has an updated InputManager.asset file that provides support for 4 attached Gamepads.

Gamepad Mapping

Depending on the device, the physical buttons and joystick axes may map to different managers in the Input Manager. For this reason before using the data from the Input manager it should be filtered by device name. Then an appropriate handling function can be called.

Recommended Controllers

  • For PC development the best controller to use is an XBOX 360 wired controller
  • For Android development the NVIDIA SHIELD is obviously a great choice.
  • For Android development the Nyko PLAYPAD PRO is a good choice as long as it is one of the newer units. The older ones (Bn: 122209 5174) appear to have incorrect firmware and are hard to update.

The Sample

The sample shows mapping of different controllers to the same internal structure and then reading from that structure. The sample also shows a simple way of detecting button down events and filters the analog channels to eliminate drift. You can get the sample here.

The sample works on PC and Android with a Gamepad connected.

GamePad support for Unity and Android

Gamepad handling libraries

There are many Gamepad handling libraries in the Unity Asset store that may provide more coverage of controller types. One that we've had experience with is InControl by Gallant Games which works extremely well.

Summary

With the launch of Android TV there will be more demand for Gamepad enabled titles on Android. Developing Unity and SHIELD is easy and fun. In an afternoon a developer can have a cross platform project set up and start development without having to worry about the complexities of low level programming or the android life cycle.