Version: 2021.2
言語: 日本語
AppCallbacks class
ユニバーサル Windows プラットフォームの Player 設定

Universal Windows Platform: WinRT API in C# scripts

It is possible to use WinRT API directly in Unity scripts. However there are limitations and requirements for this:

  • Scripts must be written in C#
  • API compatibility level must be set to .NET 4.6 or .NET Standard 2.0 in the player settings
  • 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
    }
}
AppCallbacks class
ユニバーサル Windows プラットフォームの Player 設定
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961