Unity 3D for Android Wear

Unity 3D for Android Wear

Orrery Wear – the Android Wear edition of Orrery – is now available for free on Google’s Play Store.

Porting a Unity 3D app to the wearable platform is quite straightforward, even if not yet fully supported by the Unity IDE itself.

It’s always interesting to see a new platform evolve, especially at the speed that wearables do…


Smartwatches have come a long way in a very short time – from a quite ‘dumb’ external LCD display to what is basically (in some cases literally) a second phone on your wrist.

And those little devices have become quite beefy too – they feature (last-)generation smartphone specs (and don’t have to push half as many pixels as other mobile devices).

This screams for 3D and thus Unity – so I got hold of a LG G Watch to try and bring Orrery to Android Wear.

The LG G features a Snapdragon 400 (quad core A7 cortex @ 1,2 GHz), 512MB RAM and 5GB flash – it shares those specs with Samsung’s Gear Live – the only other Android Wear watch that is available right now…

Marty McFly: “Whoa Doc, do you mean to tell me this sucker is nuclear?”
Dr. Emmett Brown: No, no, no, no, no, this sucker’s electrical.”

s001


Killing the darlings

A smartwatch is not so smart when it comes to handling user input – the limited number of buttons (exactly zero in case of Android Wear) and the tiny touch screen make complex interfaces next to impossible.

The first thing I did was to strip a lot of functionality from the original app.

Navigating a 3D viewport with your thump, while it obscures the whole screen, is also a hopeless endeavour – so I removed the camera control and set it to fly on an automated curse. It is now trailing a randomized bezier curve through our solar system.

In the end, the whole GUI was deactivated in favor of just one action: double tap to exit…

Sound was also removed, texture sizes halved and antialiasing deactivated – it doesn’t really make that much of a difference on those screen sizes anyway.

So it’s basically Orrery light – on auto pilot.

s05


From Unity to Android Studio

Now I have a working android app that should behave quite well on a smartwatch – but how to install it there?
Since Android Wear is well… Android, we can just compile with Unity as usual and side-load the *.APK to the device.

Works like a charm – in fact, I even installed the original release and ran it without issues.

But this won’t fly on the Play Store, a real wear app looks a bit different – it exists of two parts:
The phone-module, and the wear-module.

The first is supposed to run as a service and- or front end on the users mobile – the second on the wearable device itself.
While smartwatches are quite powerful, they are very limited by their battery run-time, so offloading networking and some of the heavy lifting to the phone is a good idea.

Orrery doesn’t benefit from any of this, but it still has to ride piggyback on a “phone” type app.

So I exported it as a Google project from Unity and installed Android Studio.

s08


Packaging and Publishing

The following part just reiterates parts of Googles documentation – please have a look at it here:
https://developer.android.com/training/wearables/apps/creating.html
https://developer.android.com/training/wearables/apps/packaging.html

The project was imported as “OrreryWear” and a clean Android application “OrreryWearPhone” added.

Package name, version numbers and permissions in the ‘build.gradle’ and ‘AndroidManifest.xml’ files of both applications have to be identical – I also added the line <uses-feature android:name="android.hardware.type.watch" /> to the wear app’s manifest and copied the icon-drawables over.

The phone module gets compiled with the SDK version 9, the wearable with 20 (KitKat Wear).

Finally, the wearable module is added as a dependency to the phone app:

compile 'com.google.android.gms:play-services:5.0.+@aar'
compile 'com.android.support:support-v4:20.0.+'
wearApp project(':OrreryWear')

The last step is to add the existing release key from the Unity project and compile the *.APK.

s07


 Stumbling blocks

A small issue when testing the build, was the fact, that Orrery is quite large (23MB) and took over a minute till it got transferred to the watch via BlueTooth. I guess most Unity applications will be a bit heavy on file size by nature, so you (and your users) have to be patient…

I still decided against having a phone front end, with nothing more than an info message like “please wait till this app got transferred to your watch”.

Yes, it would ‘solve’ the issue via user education which is admittedly better than nothing, but the user ends up with all those shortcuts to what are essentially dummy-apps – not ideal either.
I think this is something Google has to solve in future iterations of Android Wear (for example by just adding another installation-process notification for the wear module).

Another interesting issue is the device orientation. While this is normally a no-brainer, it seems to get a bit fuzzy with smartwatches.

I was made aware that Orrery renders 90° rotated on Motorola’s Moto 360 watch. Well… I had to chose portrait in Unity’s settings to have it oriented correctly on the LG G, but it looks like the Moto 360 needs the landscape setting.
I feel like this shouldn’t happen, granted I’m not sure if “up” is such a clear defined concept with watches who have square screens (relative to the straps I would assume) – but still this feels like a bug.

Oh, and one last thing – be sure not to use auto-orientation, a watch is seldom held level.

 

Happy porting!

17 thoughts on “Unity 3D for Android Wear”

  1. Coulter

    I saw you corrected the orientation issue on Google Play between the G-Watch and the Moto 360 – how did you do this?

    1. flashgordon Post Author

      Hi Coulter,

      I solved it like this – ugly but does the job:

      if (SystemInfo.deviceModel.IndexOf("360") != -1)
      {
      Screen.orientation = ScreenOrientation.Landscape;
      }

      Cheers!

  2. Vincenzo

    Hi .. I’m finding problems to compile all on Android Wear, the application is transferred correctly, but when I try to open it this crashes unexpectedly. You could depend on what?

    Using Unity3D 5.3.2p3 and Android Studio 1.5.1

      1. Vincenzo

        Okay, but you know I can confirm the operation of the Unity compilation on its latest versions? Because the net I find only very old guidebooks and no longer functioning …

          1. Vincenzo

            Excuse me, I meant it works! I checked out the problem with the emulator and I have solved. Therefore confirm compatibility with the latest systems :)

  3. Vincenzo

    I only have one doubt, by installing your application, I noticed that it is not present on the cell but only on the smartwatch (also from the fact playstore appears the button start after installing it). How can I get the same result? As in my case I have two app, installed on my smartphone and on my smartwatch

    1. flashgordon Post Author

      Glad you got it working, cool.

      An Android Wear app always consists of the wear-device – and the cell-device part. I just ‘hid’ the cell part by not having it add its icon to the cell’s home screen.
      It made sense to me since the cell part of the app doesn’t do anything in my case, but in hindsight it’s a bad practice…

      Users often don’t notice if the app has been successfully installed on the watch or struggle to remove it later.

      Cheers!

        1. flashgordon Post Author

          Sure, let’s see. I think I just removed…:
          android.intent.category.LAUNCHER
          … from the manifest.

          If I remember right, there was also a way to do this more gracefully via the package manager(?), but I’d still advise against it – not recommended.

          Cheers!

  4. Levent

    Hi, is there a way of getting only accelerometer and gyro data from smart watch to my unity app on phone in real time?

    1. flashgordon Post Author

      Hi Levent,

      that should be possible, but it might get a bit involved.
      And… I haven’t done it yet, so I can’t really give advice on this – sorry.

      Also, be aware that not all Smart Watches have gyro and acc.

      If you want to use a Smart Watch’s gyro/acc within a Unity app on
      a phone, you basically need to write an Android Wear app (for watch
      AND phone) that forwards that data.

      I’m a bit lost on how to exactly pass that over to Unity, either you’d
      have to rework the Unity (phone) app to BE the (phone) Wear app,
      or hack something clever in Java.

      Cheers!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="">