Adding a trial experience in your Windows game built with Unity

The case has been made that if you offer a trial mode for your game, then your purchase rate will increase along with the increase in installation footprint. I agree and I know several developers who have increased their game’s revenue by organically growing their install base using a trial mode.

Fortunately, the Windows and Windows Phone stores each make it very simple to implement such an experience. Coupled with Unity who was gracious enough to include a simple API in its platform to check for a trial license from the store platform.

Step 1 – As in game, you will need to decide the basis of your trial experience. Is it going to be:

  • 7 days with unlimited access to features?
  • Unlimited with limited features?
  • Somewhere in between?

***Let me warn you – if you don’t give the player something compelling to do in trial mode, they will *not* purchase your game. I suggesting loading up your search engine of choice – preferably Bing – and doing some research on what works as far as trial experiences.

Once you’ve decided on what your super-awesome trial experience is going to look like, you can start to implement what you need in your code.

Step 2 – On to the code!

As I mentioned above, Unity has included a simple API for probing the license information for the game from the Store platform. I wasn’t able to find any documentation for the API on the Unity docs site, so I’ll just post the code definition here.

using System;
using UnityEngine;

namespace UnityEngine.Windows
{
    public sealed class LicenseInformation
    {
        public LicenseInformation();

        public static bool isOnAppTrial { get; }

        [WrapperlessIcall]
        public static string PurchaseApp();
    }
}

Somewhere in my game scripts, I will want to query this API to see if I need to setup my game to support trial mode or the player can just proceed with normal gameplay. Typically, in a Unity game, you will have some kind of GameController object that will persist across scenes. That is where I am going to put my code for the sake of this tutorial. So, let’s open that up.

We need to store the status of trial mode in a public static field, so that other scripts that query it to limit features in the game.

    public static bool IsTrial = true;
    void Awake()
    {
        GameObject.DontDestroyOnLoad(this); // cause this object to persist

#if UNITY_WINRT
        IsTrial = UnityEngine.Windows.LicenseInformation.isOnAppTrial;
#endif
    }

After I store the state, I can use it to draw a Buy button in my game’s GUI. When the play presses the button, it will call PurchaseApp() to launch the Store purchasing process.

    void OnGUI()
    {
        if (IsTrial)
        {
            if (GUI.Button(new Rect(50, 30, 100, 25), "Buy me!"))
            {
#if UNITY_WINRT || WINDOWS_PHONE
                var receipt = UnityEngine.Windows.LicenseInformation.PurchaseApp();
                IsTrial = false;
#endif
            }
        }
    }

At this point, I can’t tell that the string that PurchaseApp returns is anything at all. I get an empty string when I debug, but I am also not debugging against a game that is published in the store. It appears to just be a fire-and-forget style API, so I want to put in some logic to recheck the trial mode state when FixedUpdate runs, but only after 1 second has passed. So, while the app is in trial mode, we will check for a change every 1 second.

    void FixedUpdate()
    {
        if (IsTrial && (Time.realtimeSinceStartup - _lastTrialCheck) >= 1f)
        {
            _lastTrialCheck = Time.realtimeSinceStartup;

            // we'll detect if the trial state has changed
            if (UnityEngine.Windows.LicenseInformation.isOnAppTrial != IsTrial)
            {
#if UNITY_WINRT
                IsTrial = UnityEngine.Windows.LicenseInformation.isOnAppTrial;
#endif
            }
        }
    }

That’s it. Hopefully, you have enough information to implement a trial in a Windows game. Remember, make the trail mode fun enough where the players will want to purchase your game to continue playing and to support the great work that you’ve done!

Cheers!

Also, here’s the full source for my GameController class.

using UnityEngine;
using System.Collections;

public class GameController : MonoBehaviour {

    public static bool IsTrial = true;

    private float _lastTrialCheck = 0f;

    void Awake()
    {
        GameObject.DontDestroyOnLoad(this); // cause this object to persist

#if UNITY_WINRT
        IsTrial = UnityEngine.Windows.LicenseInformation.isOnAppTrial;
#endif
    }

    void FixedUpdate()
    {
        if (IsTrial && (Time.realtimeSinceStartup - _lastTrialCheck) >= 1f)
        {
            _lastTrialCheck = Time.realtimeSinceStartup;

            // we'll detect if the trial state has changed
            if (UnityEngine.Windows.LicenseInformation.isOnAppTrial != IsTrial)
            {
#if UNITY_WINRT
                IsTrial = UnityEngine.Windows.LicenseInformation.isOnAppTrial;
#endif
            }
        }
    }

    void OnGUI()
    {
        if (IsTrial)
        {
            if (GUI.Button(new Rect(50, 30, 100, 25), "Buy me!"))
            {
#if UNITY_WINRT || WINDOWS_PHONE
                var receipt = UnityEngine.Windows.LicenseInformation.PurchaseApp();
                IsTrial = false;
#endif
            }
        }
    }
} 

Porting your Unity game to Windows Phone – Part 1

I just wanted to cover some stuff that you need to handle when porting your Unity game to Windows Phone. What’s required to get started and what’s required to pass store certification.

First, let’s cover what’s required to get started.

  • Unity 4.3.3 or higher
  • Windows 8.1 x64(to run the emulator)
  • Visual Studio 2013/2012
  • Windows Phone SDK
  • Developer account

Now, you should already know how to get the latest version of Unity. If not, then you probably shouldn’t be reading this blog post, but rather this getting started page on Unity’s own site.

How do I get the other stuff?

Windows 8.1

Windows 8.1 is installed on most new PCs, so that is one route to go. You can also purchase a copy and install it from here or any other retailer.

-OR-

If you are a student enrolled at school who has DreamSpark Premium or a startup who has a BizSpark account, you can download Windows 8.1 for free.

Visual Studio

You can always start with the free version of Visual Studio 2012 for Windows Phone found here. You can also take advantage of DreamSpark/BizSpark and download Visual Studio 2013 Ultimate from your associated account (which is what I would do. I mean, why not?)

Windows Phone SDK

If you’re lucky enough to grab a copy of VS 2013 Ultimate, or you decided to use VS 2012 for WP, then the Windows Phone 8 SDK come with both of those by default. If you have another version of visual studio, you can download the SDK as a separate install from here.

Important note about running the emulators – your PC hardware must support hardware-assisted virtualization, SLAT, hardware DEP and have a minimum of 4GB of RAM on top of running Windows 8.1 x64 in order to run the emulator. This should not be an issue with most modern hardware. However, you may need to enable these things in your BIOS.

Developer Account

Again, this is a good place to use your DreamSpark or BizSpark benefits if you have them, since you get a free developer account with each. If it’s just you then you will need to shell out $19 for yourself to register or $99 for your company to register. You can started with that process here. NOTE: to access your free developer account benefit, you will need to grab the code from your DreamSpark/BizSpark account page and enter it in at checkout when registering on the developer account page.

Exporting your game

Once you have all of the tools and that incredibly awesome game that you built, you will want to export the game from Unity into a Visual Studio solution, so that you can build and debug the project. Let’s take a look at that process.

  1. Open File->Build Settings in Unity and select Windows Phone 8. NOTE: If you plan on profiling your game from Unity, then check Development Build to enable that.
  2. Press Build and select an output folder for your game’s Visual Studio Solution. I usually create a folder under my main project folder to hold this output.

 

Once you get your Visual Studio solution output, you can open it and do a few things to run your game.

If you have a Windows Phone device that you would like to run your game on, make sure it is developer unlocked. If you’ve never done this before, you can follow the instructions found here.

Once your phone is connected to the PC via USB cable, you can build, deploy and debug right from Visual Studio to your device by pressing the Run button.

If you don’t have a Windows Phone device to run on, you can run your game using an emulator. In Visual Studio, simply select this drop-down and select the applicable emulator. As noted above, your machine needs to be capable of running the emulator!

The fun stuff!

…otherwise known as – certification. What do you absolutely have to add to or handle in your game in order to pass store certification? Let’s take a look.

Privacy Policy – If you game accesses the internet for any reason, including advertising, you must have a privacy policy readily available for the player to read – whether it’s hosted directly in your game or just a link to a web-hosted policy. See section 2.7.2 in the certification requirements for more details – http://msdn.microsoft.com/en-US/library/windowsphone/develop/hh184841(v=vs.105).aspx

Location Services – if your game makes use of location services, then you not only have to have a privacy policy, then you must provide a way for the user to opt-out without crashing the application. This can simply be a message that tells the player that location is a required game mechanism.

The Back button – Windows Phone requires handset manufacturers to implement a hardware back button for a consistent user experience. Because of this, your game should behave similar to the guidance below in order to pass certification.

  • During gameplay – present a pause menu/dialog or navigate to the previous menu. For example, in a simple game, you may simply want to return to the main menu of your game when the back button is pressed.
  • In the pause menu/dialog – pressing the back button should exit the menu/dialog and resume the game.
  • In the main menu – if the back button is pressed during the main menu, then your game should exit.

Here’s a code sample of handling the back button in Unity

 

Next post, I will go into adding tailoring the splash screen experience, handling orientation, and pausing and resuming. As always, I welcome any questions in the comments section.

 

Cheers!

Office Hours @ UT Arlington

I have setup a time to be on campus at UT Arlington in March.

I will be in the ERB – room 670 from 11:00 AM – 2:00 PM on March 3rd. There are four 45 minute time slots that you can sign up for here.

I am available to discuss anything you would like – building apps, building video games, career advice, anything to do with Microsoft, etc. I am there for the students, so sign up now and take advantage of my time!

Cheers!

 

Unity Events @ Microsoft

Back in December, my colleague, Nathalie Goh-Livorness, and I sat down and looked at the landscape of what was out there in the indie game developer scene and Unity seemed to be popping up just about everywhere – for good reason. Unity is an awesome toolset and its cross-platform capabilities are unrivaled.

Starting in February, Microsoft offices across Texas, Illinois and Ohio will begin hosting events called “Day of Unity”, in conjunction with Unity, which will consist of beginner content designed to teach people the Unity toolset and a porting lab that is designed to help those who’ve already built games using Unity to bring them to the Windows platform.

To find out more about the Day of Unity events and to find out how to sign up to attend one, please go to my landing page. There, you will find the agenda for the day along with links to the respective registration pages.

Peace out! and the Lego Movie is awesome!

Roundup of Unity tutorials and resources

I was asked earlier this week to share some of my favorite tutorials and resources for getting started using the Unity3D game engine. Well, here they are!

Windows related resources:

Heads up. Starting in February, Microsoft will be hosting “A Day of Unity” events at the three offices in Texas – where we will offer a beginner’s course where the attendees will walk through building their first game with Unity. Stay tuned for a blog post showcasing these events next week!

As I find more resources, I will update this blog post. If anyone has any to share, please post it in the comments and I will compile it later.

Thanks!

Jason

Wrapping up 2013

An impromptu look at some of what I did in 2013.

A Big Change

In December, I moved from being a Premier Field Engineer to a Technical Evangelist with Microsoft. The role is slightly less technical, but I will get to do the things I truly enjoy – connecting with my peers in the developer community and working with folks who are building video games. This job really is a dream come true and I couldn’t be happier with the move. Having said that, my friends in PFE will always hold a special place in my heart and will remain my go to place for technical assistance, because they are the best! *seriously*

While I was in PFE, I helped build a program call App Consult. It is a wonderful program designed to help developers who feel like they need that extra little push to get their app over the finish line. If you want to find out more, you can view my blog post about it here.

New technologies

Windows 8.1 – I was lucky enough to be around for the early stages of the Windows 8 launch and the push to bring quality apps to the new Windows Store back in 2012. On October 18th, 2013, we launched Windows 8.1 with much praise. We listened to customer feedback and acted upon metrics gathered from Windows 8 users. We learned about all of the new changes for developers and there were a lot of positive changes.

Xbox One – Yeah, I jumped into the Xbox One craze a week after it started. I made the mistake of not pre-ordering one, but I was lucky enough to pick one up at a local store a week after launch after the Black Friday stock was replenished. I have to say, despite some glitches that I am sure will get worked out, it has been an awesome experience so far.

Awesome events

I got to go to some truly awesome events this year.

  • Build in June was my # 1 – The amount of connections and information I was able to take away from this conference was incredible! The technology showcased was awesome and I really enjoyed interacting with developers at the hack-a-thon.
  • Cowtown Code Camp – This little gem took place in March in downtown Fort Worth, TX. It was very well executed for an inaugural event and I had a serious sense of pride that it was happening in Fort Worth. Great job to the team that put this together and I hope there are many more!
  • BigDesign in Dallas, TX – I didn’t get to attend the second day of this conference, but I truly enjoyed the first day. The highlight was Robert Gabhart’s session. If you ever have the chance to watch this man speak, don’t miss out.

New friends

Earlier in the fall, I really started to reach out into the community as I was tooling up for interviewing for the evangelist position and I made some great new friends in the process. A special shout out to the folks at the Fort Worth .NET UG, DFW Mobile .NET UG, Dallas Unity group, DalMob, Dallas Society of Play and the Dallas chapter of the IGDA.

I hope everyone had as awesome of a year as I did in 2013 and here is to an even better 2014. Cheers!

Now some pics to liven up the post

Figure 1 – entrance to the //build/ conference the Moscone Center in San Francisco

Figure 2 – The hack-a-thon at //build/

Figure 3 – McGuire’s Irish Pub in Pensacola, FL – taken on vacation.

Figure 4 – that’s me with Randy Pitchford at the Gearbox Software Community day in September

Figure 5 – my new toy – 2013 Scion FR-S

 

P.S. I’m still sick about the Dallas Cowboys losing to the Eagles, but let’s all hope Jerry sees the light soon!

 

Windows Store Devs – Get yourself an App Consult!

I wanted to let everyone know about a great service that Microsoft is offering through our Global Business Support group. It’s called App Consult and it enables evangelists like myself to get expert, one-on-one help for the Windows Store developers we’re working with in the community. Here’s the best part – it’s absolutely FREE.

Things you can get help on(currently only applies to Windows Store apps, but Windows Phone support is planned for early next year):

  • Design guidance
  • API usage
  • Best practices
  • Debugging
  • Performance

If you’re developing a Windows Store app and this sounds like a service that you would like to take advantage of, please reach out to me or your local Tech Evangelist and ask them for an App Consult. If you’re not sure who that is, you can look them up for the US here, or ask me and I can find out.