Version: 2019.3
AppCallbacks 类
通用 Windows 平台 Player 设置

通用 Windows 平台:C# 脚本中的 WinRT API

可在 Unity 脚本中直接使用 WinRT API。但是,这种情况存在限制和要求:

  • 脚本必须用 C# 编写
  • API 兼容性级别必须在播放器设置中设为 .NET 4.6 或 .NET Standard 2.0
  • 由于 Unity Editor 也使用相同的脚本代码(但始终使用 Mono),所有使用 WinRT API 的代码都必须位于 ENABLE_WINMD_SUPPORT 定义之下

以下是直接使用 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
    }
}
AppCallbacks 类
通用 Windows 平台 Player 设置
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961