Version: 2018.2 (switch to 2018.1 or 2017.4)
AppCallbacks class
Universal Windows Platform Player Settings
Other Versions

Universal Windows Platform: WinRT API in C# scripts

It is possible to use WinRT API directly in Unity scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary
. However there are limitations and requirements for this:

  • Scripts must be written in C#, it’s not possible to use WinRT API from UnityScript
  • Scripts must be compiled using Microsoft’s compiler, not Mono. This requires to set compilation overrides to Use .NET Core or Use .NET Core Partially, in the later case scripts must not be under PluginsA set of code created outside of Unity that creates functionality in Unity. There are two kinds of plugins you can use in Unity: Managed plugins (managed .NET assemblies created with tools like Visual Studio) and Native plugins (platform-specific native code libraries). More info
    See in Glossary
    or Standard AssetsA collection of useful assets supplied with Unity. Unity ships with multiple Standard Asset such as 2D, Cameras, Characters, CrossPlatformInput, Effects, Environment, ParticleSystems, Prototyping, Utility, and Vehicles. More info
    See in Glossary
    folders
  • Because the same script code is also used by Unity Editor (which always uses Mono), all code that uses WinRT API must be under ENABLE_WINMD_SUPPORT define

Below is an example for getting advertising using WinRT API directly:

using UnityEngine;
public class WinRTAPI : MonoBehaviour {
    void Update() {
        auto adId = GetAdvertisingId();
        // ...
    }

    string GetAdvertisingId() {
        #if ENABLE_WINMD_SUPPORT
            return Windows.System.UserProfile.AdvertisingManager.AdvertisingId;
        #else
            return "";
        #endif
    }
}

Note: when using IL2CPPA Unity-developed scripting back-end which you can use as an alternative to Mono when building projects for some platforms. More info
See in Glossary
scripting backendA framework that powers scripting in Unity. Unity supports three different scripting backends depending on target platform: Mono, .NET and IL2CPP. Universal Windows Platform, however, supports only two: .NET and IL2CPP. More info
See in Glossary
, this is only supported when using .NET 4.6 compatiblity profile.

Did you find this page useful? Please give it a rating:

AppCallbacks class
Universal Windows Platform Player Settings