可在 Unity 脚本中直接使用 WinRT API。但是,这种情况存在限制和要求:
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.