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

Universal Windows Platform: WinRT API in C# scripts

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

  • Scripts must be written in C#
  • Скрипты должны быть скомпилированы с помощью компилятора 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
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961