包含此页的版本:
不含此页的版本:
Unity 在为通用 Windows 平台生成时包含 Windows 运行时 (WinRT) 支持IL2CPP Unity 开发的脚本后端,在为某些平台构建项目时,可以将其用作 Mono 的替代方案。更多信息
请参阅术语表脚本后端。使用 Windows 运行时支持直接从托管 (C#) 调用本机系统 Windows 运行时 API 和自定义 .winmd 文件脚本一段代码,允许您创建自己的组件、触发游戏事件、随时间修改组件属性以及以您喜欢的任何方式响应用户输入。更多信息
请参阅术语表和插件。
Unity 会自动引用 Windows 运行时 API,例如Windows.winmd在通用 Windows 平台上。若要使用自定义 .winmd 文件,请将它们与任何随附的 DLL 一起导入 Unity 项目文件夹并进行配置。有关详细信息,请参阅导入和配置插件。
若要在 Unity 脚本中使用 WinRT API,请执行以下作:
ENABLE_WINMD_SUPPORT 指令。这是必要的,因为编辑器使用单声道Unity 中使用的脚本后端。更多信息以下代码示例直接使用 WinRT API 获取广告 ID:
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
}
}