Version: 2018.1
Класс AppCallbacks
Universal Windows Platform Player Settings

Universal Windows Platform: WinRT API in C# scripts

Существует возможность использования WinRT API прямо в Unity скриптах. Однако, есть ряд требований и ограничений:

  • Скрипты должны быть написаны на C#, невозможно использовать WinRT API из UnityScript или Boo
  • Скрипты должны быть скомпилированы с помощью компилятора Microsoft, не Mono. Это требует установки переопределений компиляции в “Use .NET Core” или “Use .NET Core Partially”, в последнем случае скрипты должны находиться не в папках “Plugins” или “Standard Assets”
  • 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

Ниже представлен пример получения идентификатора рекламы напрямую с помощью WinRT API:

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 IL2CPP scripting backend, this is only supported when using .NET 4.6 compatiblity profile.

Класс AppCallbacks
Universal Windows Platform Player Settings