MarkerMetro / MarkerMetro.Unity.WinLegacy

Windows Store & Windows Phone Unity Plugin - Implements missing .Net APIs
https://www.nuget.org/packages/MarkerMetro.Unity.WinLegacy/
MIT License
10 stars 4 forks source link

Getting Started

Unity Plugin for Windows Universal 8.1 (Windows 8.1 and Windows Phone 8.1) used when porting existing code bases which have used Mono/.Net APIs not supported by WinRT.

Not all unsupported WinRT/Windows Phone APIS are implemented, or implemented well by Unity. Where this is the case, we have implemented this plugin to help.

It is recommended to use methods implemented by Unity wherever possible, however missing APIs are still available under MarkerMetro.Unity.WinLegacy.Plugin namespace

See the Unity FAQ on Universal Apps which contains a complete breakdown of the platform conditional compilation you can use with Windows Apps and also broad guidance around the special plugin folders on Windows apps.

build status CI

build status Release

Prerequisites

Getting Latest

Build Latest from Source

We recommend using the latest stable tagged release, or you can build straight off the head if you are brave.

Configure the solution to Release | Any CPU and Rebuild.

You can then copy the folder contents as follows:

Download Latest Stable Binaries

Alternatively, you can download latest from Nuget

Extract the files from the package and copy the folder contents as follows:

Note: The Metro output will work fine for Universal projects with both Windows 8.1 and Windows Phone 8.1

Initialize the Plugin

Within your Windows application, just need to ensure you initialize the plugin appropriately with examples as follows:

For Windows Universal and Windows 8.1 Apps add the following method to App.xaml.cs and call it after the call to appCallbacks.InitializeD3DXAML().


void InitializePlugins()
{
    // wire up dispatcher for plugin
    MarkerMetro.Unity.WinLegacy.Dispatcher.InvokeOnAppThread = InvokeOnAppThread;
    MarkerMetro.Unity.WinLegacy.Dispatcher.InvokeOnUIThread = InvokeOnUIThread;
}

For Windows Universal and Windows 8.1 Apps the handlers should be as follows:

public void InvokeOnAppThread(Action callback)
{
    appCallbacks.InvokeOnAppThread(() => callback(), false);
}

public void InvokeOnUIThread(Action callback)
{
    appCallbacks.InvokeOnUIThread(() => callback(), false);
}

You can see existing implementations in WinShared here:

You can easily debug a particular Windows Store or Windows Phone plugin project as follows:

  1. Add the platform specific WinLegacy project to your solution (e.g. MarkerMetro.Unity.WinWinLegacyMetro)
  2. Build platform specific WinLegacy project in Debug and copy output to Unity(e.g. /Assets/Plugins/Metro)
  3. Build from Unity
  4. Set breakpoints in your platform specific WinLegacy plugin project and then F5 on your app

Guidance for Usage

Wherever possible you want to minimize the changes to existing code, therefore we recommend applying a using statement for the platforms you need to provide support for. The following example ensures support for TcpClient for all Windows platform outputs

#if (UNITY_WINRT && !UNITY_EDITOR)
using TcpClient = MarkerMetro.Unity.WinLegacy.Net.Sockets.TcpClient;
#else
using TcpClient = System.Net.Sockets.TcpClient;
#endif

You can replace namespaces, files and use the extension classes provided as required. The general approach is to mimic the underlying .Net namespaces and implenentation as much as possible so there is minimal change required to legacy code bases when porting.

Use WinShared to make things easier

If you are starting a new port and/or you want the best ongoing Unity integration with WinLegacy and related plugins, consider MarkerMetro.Unity.WinShared.

This will provide features such as:

Please Contribute

We're open source, so please help everyone out by contributing as much as you can.