Donut Get! running on Windows Phone 8
Earlier this year I jumped into Windows Phone 8 when I got a Nokia Lumia 920. I’d been using an iPhone 3G for about 4 years and was ready to move on to something a bit more… modern. While Windows Phone has its crappiness (you mean I can’t save image attachments from e-mails???), iOS had its fair share of crappiness early on as well (no copy & paste???).
It was great to have a new fancy phone but I had an empty place in my heart because I couldn’t play my Sokay Games on my phone…
Bless the gurus at Unity for bringing the Windows Phone 8 exporter to Unity 4, and for free as well!
A couple weeks ago I tested out the WP8 exporter by doing a quick port of Donut Get! I got it working within an hour. I still need to polish it for release, but it was surprising how little extra it required me to get it running. In this post I will cover some of the process and the gotchas I encountered along the way.
Visual Studio Express for Windows Phone
- Unity 4.2+
- Windows 8
- A Windows Phone with Windows Phone 8
- Visual Studio / Visual Studio Express for Windows Phone
YES, Windows 8 is a requirement. Not XP, Vista, 7, ’95 nor 3.1. From what I understand it’s because of the “Hyper-V” requirement. I looked online and there’s complicated hacks to install just the required files on Windows 7 but that’s too much work for me! Just try it in your Windows and see what happens.
Visual Studio Express for Windows Phone is free to download but it’s in 30-day trial mode unless you register on their site. Love to jump through hoops!
If you’re on a Mac and you’d like to run Windows 8 in a virtual machine, it’s my understanding that you’ll need at least Parallels 8. Windows Phone development apparently requires “Hyper-V” (whatever that is) to run the Windows Phone emulator. I actually don’t know if using this emulator is an absolute requirement for development since I intend to test on a device anyway.
In Parallels’ configuration panel, make sure “Nested Virtualization” is enabled!
Other VM software will likely work as well — VMWare, Virtualbox, etc. You won’t find info here, though. Google it! Or… err… Bing it? 😉
Register as Windows Phone Developer
You must register as a Microsoft developer on the Windows Phone developer site. The fee is currently $19/year. It was previously $99 until a recently promo, so they’ve possibly dropped the fee permanently or just for an extended period. Once you’re approved as a Windows Phone developer, you’ll be able to unlock your phone and build apps for it.
Before diving in, make sure you’re not using any features that aren’t supported. You can find out on the Getting Started page. I found out the hard way that using Animation for script variables wasn’t functional.
Thinking about it, I believe the changes I needed to make to Donut Get’s code were minimal. In places where I used the accelerometer, I added an additional directive for Windows Phone 8.
Vector3 dir = Vector3.zero;
dir.x = -Input.acceleration.y;
dir.y = Input.acceleration.x;
dir.x = -Input.acceleration.x;
dir.y = Input.acceleration.y;
dir.x = -Input.acceleration.y;
dir.y = Input.acceleration.x;
Also, in places where I checked for the RuntimePlatform, I used this:
if (Application.platform == RuntimePlatform.WP8Player) PLATFORM = "wp8";
I also got stuck for a while on an NGUI bug where my checkboxes would rarely update when tapping them. Updating NGUI to the most recent version (which apparently had some WP8 fixes) solved the problem.
The accelerometer data coming out for the Windows Phone version seems to be much more jittery than Android and iOS, so I may have to add some functions to smooth out the results a bit.
Application.OpenURL() doesn’t work!
Ok, this is very annoying. When calling OpenURL(), the app just quits on WP8. Fortunately there’s a decent (hacky) workaround.
You can pass the URL to open to the native WP8 layer of the app by modifying visual studio. You can create a static class and modify the MainPage.xaml.cs to listen to it and open a URL. Here’s the post I found with an example of doing that:
iTween is a No-No!
I found out the hard way that iTween has issues with Windows 8 and Windows Phone 8. From my understanding, this is because they don’t support Hashtables that type aren’t native to .NET, only MONO.
My solution was to use HOTweenMicro, which I actually prefer to use over iTween. Much better speed, from my experience and I prefer the API. Also, you need make sure to use HOTweenMicro, and not regular HOTween with WP8. Again, some library incompatibilities.
Exporting from Visual Studio
Once everything is setup, running the project is a breeze.
Just hit that Play button, yo!
Change My Icon
Unity won’t set your project icon so you can replace the image in your project (PROJECT/Assets/ApplicationIcon.png). It’s 100×100 and transparent areas will use the system’s tile color.
Also, you’ll have to create Tile icons within the “Tiles” folder. Just replace the default ones Unity creates. These icons will show up when you use the App as a Tile.
Oh Snap, My Audio is Choppy!
So a common problem apparently is choppy audio. I believe this has something to do with the debug stuff running in the background of your app. In fact debug data will show on your screen when your game is running while the phone is still connected to the computer running Visual Studio.
The solution for choppy audio as far as I know is simply switch the build mode to “Master” — the default is “Debug”. “Master” is the setting you’ll use to export a XAP for the Windows Phone store. “Release” is for profiling — it has debug data ripped out but still runs the profiler.
I couldn’t find a way to receive the debug logs output from within Visual Studio. From what I read on the Unity site, you can supposedly dig up a .log file on the phone but I’d prefer something a bit more immediate. Does anyone know how to do this?
Yeah, it was actually pretty simple once everything was setup. As I mentioned, I haven’t released the app yet so there may be other things to look out for. One thing I was trying to figure out was finding a way to move the game into the “Games” app instead of the default App list.
Let me know if there’s other quirks to this process as I’ll continue update this as I learn more about the process.
- Official Unity Windows Development Forum
- Windows Phone Developer site
- Getting Started with Unity 3D on Windows Phone