Wednesday, April 11, 2012

When Unity gets along better with Android than iOS...

I have been toying with Unity 3D for a few weeks, following the decision to transition development of a game I am collaborating to a powerful and more designers friendly environment as requested.
I have to give the Unity team props for the improvements in Unity 3.5 - for example the improved versioning/Git support - and for the decision to give many developer a chance to get a good look at Unity on mobile platforms by giving out licenses for Unity Basic on iOS and Android. One does not work too well right now and the other one works better than I expected.
Unity's power is not really the result from the many strong features of the engine - multiple cameras support and compositing is so powerful it's not even funny - or from the languages you can use to write code for it, but from the central editor which ties it all together.  Through custom scripts and plugins you can extend the editor and shape it just the way it suits your project best.

Unity Editor
The basic workflow - this post is not intended to be a big Unity overview or a collection of Unity references, but just a way to wet your appetite so to speak - consists in adding objects to the scene and give them life through customized behaviors chosen from built-in behaviors and new ones you can write yourself with prototyping friendly languages such as JavaScript which I will talk about in a follow-up post a bit more, especially for what concerns Unity... just know that there is plenty to be happy about (classes, inheritance, performance, etc...). 
MonoDevelop IDE
Naturally, this makes it easier for pure coders, level designers, sound designers, and artists to work together and quickly iterate on the product: the coders implement the requested behaviors and exposes to the editor the right knobs and levers the designers need to tweak to test gameplay ideas. It is an environment that is quite mature under that aspect, although not nearly bug free, but as some crazy scientist told me this morning "the bigger the project - the worse the tools", so I guess that the lesson to be learned here is to be glad when there are so few of them :). Jokes aside, I am glad such a versatile multiplatform engine is around and is on MacOS X too!

Seeing the code run on the Unity Game window is one thing, watching it run on device is an other experience entirely in my opinion. So, I wanted to see the code running on the iPhone and test a virtual joystick solution, but it appears that Unity still has to add support for the Xcode release needed to build applications for iOS 5.1 and its SDK (note: you must use this SDK and the latest stable release of Xcode to submit applications to the Apple App Store, even though the final app might also run on a lower iOS release). The application crashes on device just when it checks for the correct inclusion of the Unity splash screen - Unity embeds it in the application by default - which you cannot remove unless you purchase the Pro license. Unity checks for the splash screen, it does not seem to properly detect it, and triggers an assert.Aside from an apparently outdaded ~/.android/debug.keystore file which I manually deleted and asked Unity to re-create from scratch, getting the current build to run on Android was quite easy, but the best thing about it was that it automatically recognized the Xperia Play's hardware keypad and its D-Pad was already mapped to the Vertical and Horizontal axis so the PC code could move the character on Android without the need of any virtual joypad at all. It is pretty easy to tackle the Xperia Play controls with Unity 3D as you can also see from this interesting blog post/tutorial.
I had not turned this handset on in a while, a bit disappointed with its performance and other hardware related annoyances (if you price a touchscreen device over $300 and do not give Guerrilla Glass level coating on top of the screen then do not release such device, please). Disappointed also because, thanks to its physical game controls, it had so much potential to be a major force in the Android gaming scene and Sony decided to throw it out there without letting it cook a bit more in the oven. Still, I am glad to be able to try the code on it and work on a solution that is able to handle both touchscreen only iOS devices as well as Android devices with or without a hardware keypad designed for games like the Xperia Play has. The game seems to run pretty well so far too.
Getting the input from the hardware buttons is simple, but detecting whether to show the virtual pad on screen or not is slightly more difficult, but not impossible thanks to the vibrant Unity community. I was able to find a good solution to detect if the keypad was present and opened and adapt it to my needs (C# --> JavaScript) and share it back to the community which was also helpful for me as I learned quite a few things about the Unity-Android side of things too :). You can find the Unity forum thread and the code HERE

I hope you are having fun with Unity too. Have a nice day!

P.S.: I forgot to add a few more Unity and Keypad related resources that might be of some help to you. So, here are the complete list of Xperia Play related resources I wanted to mention in this post:
Detecting keypad support
Xperia Play Unity Tutorial
Handling Xperia Play's keypad input

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...