In this thread, we will see how to interact between Unity and our WP8 or Windows Store apps.

Introduction

When you work with those platforms with Unity, it will create a Visual Studio solution with all the basics of a new solution for this kind of project (App.xaml, MainPage.xaml, …) adapted to be able  to start your game.

In this new solution, we can have access to all the framework of this platform, it’s platform specific.

Create a gateway

We want to be able to launch a platform specific action, like sharing a picture, in our Unity source code that can be handle by our WP8/Windows Store project.

using System;

/// <summary>
/// Windows specific and interop between Unity and Windows Store or Windows Phone 8
/// </summary>
public static class WindowsGateway
{
	public static Action<string, string, string> OnActionWithParametersRaised = delegate { };

	public static Action OnActionRaised = delegate { };

	static WindowsGateway()
	{
		OnActionWithParametersRaised = delegate { };
		OnActionRaised = delegate { };
	}
}

We use a static class with empty delegates. Those delegates will be handle in our platform specific project, in the MainPage.xaml.cs for example.

namespace MyUnityApp
{
	public partial class MainPage : PhoneApplicationPage
	{
		// [...]

		private void Unity_Loaded()
		{
			// [...]

			WindowsGateway.OnActionWithParametersRaised += OnActionWithParameters;
			WindowsGateway.OnActionRaised += OnAction;
		}

		private void OnAction()
		{

		}

		private void OnActionWithParameters(string url, string title, string message)
		{

		}

		// [...]

	}
}

That’s all :)