With our game RoundPingis released on phone and television we wanted to put the the game on the wear platform. Since Unity does not support Android Wear out of the box, there where a few things we learned that we want to share. If words and pictures are too much for you, we’ve added a tl;dr and an example project at the bottom of this article.
The game on other devices are in landscape, android wear devices are square, or better still, round. This is just one of the differences that made us make a copy of the game to start from. First off, resolution was changed from 16:9 to 1:1. 400×400 pixels seemed like a good size to start with. Then all graphics that needed cutting got cut. Use imagemagick’s convert terminal tool like this:
mogrify . -gravity center -extent 400×400 *.jpg
Then we just needed to align the UI components.
Furthermore one of the fun things was to remove stuff like Facebook integration, Sharing framework, rate my app and the link to our homepage (http://www.pastille.se), all gone. No need to keep those features in, and besides, everything that takes deployment time down is awesome. Deploying to your wear device is straightforward, two ways we found. The first way is to connect your android device to your computer so that you have and adb connection up. Then in the wear app start bluetooth debugging and do the same thing in your wear device. then you can start a port forward from your mobile to your wear with
adb forward tcp:4445 localabstract:/adb-hub
adb connect 127.0.0.1:4445
Then lucky you, all data is transferred to your phone over usb cable and then to your wear from your phone over bluetooth. This is tedious and time consuming, you should not do this unless you are in a pinch. You should instead use the charging cable from your wear and hook it up to your computer directly. Much faster.
Getting to work on the wear platform.
So now that was not impossibly difficult, and we now had the game on the wear.
It’s was now running on hardware, but the little wonky, because it tried to change orientation all the time. Even with everything totally still. This was solved with a script that set the orientation to portrait. While researching this we found out that this was solved before, and to a greater extent. Someone had the a problem with the Motorola 360, and it that particular device was 90 degrees rotated compared to the “correct” way. So I added that into the script as well.
Nice, but a little laggy. Time to kill darlings, because you have to. By enabling and disabling different features we managed to get the frame rate up from sluggish 12 to ok-ish 44 on the Huawei wear. Fastest on render setting did a little. Particles was also expensive so they had to go. And to our surprise, removing the music and just keeping one sound effect from the ball made a huge jump. Something like 10fps. Now this is a 2d game, that is kept intentionally clean. 3D games might require other tricks.
- Publishing on the app store
To get your app into the google play store you need to upload it with an accompany app that runs on the mobile device. this is because there is no way to uninstall apps on a wear. This is not supported by Unity so we exported the game from Unity to an Android Studio project. Then created a new android studio project for a wear and then we did like dr Frankenstein and added the pieces together in an unholy way. Take a look at the example project we added for you. Specifically the gradle files and the manifest files. Pro-tip, don’t use minify it makes Unity crash.
Wear uses something called a boxed layout. Think of it as a circle with a box inside it. Everything should be inside the box. This is because the devices with chin, aka flat tire, aka why would they do this? I don’t know, probably something technical and monetary. What I do know is that if you use this: graphics as a background in your project and then and put all your UI elements inside it the square, you are more then safe.
- Longpress to exit.
Now that the game is ready, just upload and release right? Nope, since we took over the whole screen and disabled the swipe to go back. Well Unity does that for us, for plain vanilla Android (without added Unity) you can just add a view that does all that. In Unity it was a bit more work. But we solved it all by subclassing the unityplayer and add the view from Java. Have a look in the file called UnityPlayerActivity.java and you will se the GestureDetector instantiation and creation. This I would not have found if the kind people at google that does the testing on device (there is, and it is awesome) hadn’t spotted this, my test device has a button that can go back.
- Orientation pt2
Speaking of the nice people at wear testing at Google, they also spotted that the orientation was off on the Motorola, and then later at other devices. This was very, very annoying (to me), since the old solution of getting the device name did not work. Neither did asking Unity if the screen was round, and if so, did it have se same width and height. Something that you can get from java. Luckily for us there existed a project https://github.com/tajchert/ShapeWear that we could put into our already subclassed Unity player. We added checks to what kind of display it was (round but width != height) and then it’s the chinned variant of devices, setting the orientation to landscape while otherwise setting it to portrait. All functionality setting the orientation from Unity was removed, and I wasted your time by rambling on about it. But not as much time as I wasted for the poor testers at google that really worked as my compilers. (Since I did not have a Motorola 360 or any of the Fossil devices)
A few notes about the example project.
No Unity binaries is distributed, but we added helpful text-files on where to put them.
The gnome is not public domain, it’s Pastilles property, Shapewear has it’s own license.
A lot of obstacles was tackled and now we have released Roundpingis for wear, and to help you release your Unity projects take this .zip file with a template project.
If you enjoyed this article, you can always support us buy buying some of our games.
The authors name is Johan Larsby, stalk me on LinkedIn
Pastille, is a Swedish game studio. We create fun, casual and non-violent games for the whole family and believe that playing is one of the most important cornerstones in life. You can find us on Facebook.