Version: 2023.2
언어: 한국어
Debug generated C++ code
AppCallbacks class reference

WinRT API in C# scripts for UWP

You can use the WinRT API directly in Unity scripts when you have Windows Runtime support enabled. For information on how to use the WinRT API and enable Windows Runtime support, refer to Windows Runtime support.

You need to meet the following requirements to use WinRT API in your Unity scripts:

  • Your scripts must be written in C#.
  • Your API compatibility level must be set to .NET 4.6 or .NET Standard 2.0 in the Player settings.
  • All the code that uses WinRT API must be under the ENABLE_WINMD_SUPPORT directive. This is necessary because the Editor uses Mono, which doesn’t support WinRT APIs.

This code example demonstrates how to get 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
    }
}

추가 리소스

Debug generated C++ code
AppCallbacks class reference
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961