Version: 5.6
AppCallbacks 类
WSA Player Settings

Windows Store Apps: WinRT API in C# scripts

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

  • 必须用 C# 编写脚本,不能使用 UnityScript 的 WinRT API
  • 必须使用 Microsoft 的编译器来编译脚本,不能使用 Mono。因此,必须将 Compilation Overrides 设置为 Use .NET CoreUse .NET Core Partially,在后一种情况中,脚本不得位于 PluginsStandard 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 NETFX_CORE define
  • If you want to use Universal Windows 10 API, use WINDOWS_UWP define.

Note, that NETFX_CORE or WINDOWS_UWP is defined by Visual Studio when compiling code for Windows Store Apps, so it can be used in any C# code, not just Unity scripts.

以下是直接使用 WinRT API 获取广告信息的示例:

using UnityEngine;
public class WinRTAPI : MonoBehaviour {
    void Update() {
        auto adId = GetAdvertisingId();
        // ...
    }

    string GetAdvertisingId() {
        #if NETFX_CORE
            return Windows.System.UserProfile.AdvertisingManager.AdvertisingId;
        #else
            return "";
        #endif
    }
}

Note: this is currently supported only on .NET scripting backend.

AppCallbacks 类
WSA Player Settings