Unity 提供了一些工具可用于在开发过程中测试应用程序。就像任何其他 Unity 应用程序一样,这些工具可让您调试自己的应用程序,还能以无线方式将内容推送到设备。这些工具中有一些工具仅适用于特定的 WMR 设备,例如 HoloLens。
使用沉浸式 Windows Mixed Reality 设备时,可直接在 Unity Editor 中测试和迭代应用程序。确保 Windows Mixed Reality Portal 已打开且头盔处于激活状态,然后按 Editor 中的 Play 按钮。现在,应用程序将在 Editor 中运行,同时还渲染到头盔。
对 Mixed Reality 设备使用 Play in Editor 时,需要考虑以下几个限制:
键盘、鼠标和空间控制器可在 Editor 中工作,但前提是 Windows 和 Unity 能识别它们。
非 Windows Mixed Reality 输入设备仅在游戏窗口获得焦点时才有效,否则键盘和鼠标控制可能无法正常工作。
Holographic Emulation(全息仿真)允许直接在 Unity Editor 中对 Microsoft HoloLens 项目进行原型设计、调试和运行,无需在每次希望查看应用更改的效果时都要构建和运行应用程序。这样可以极大缩短在 Unity 中开发 HoloLens 应用程序时的迭代间隔时间。
Holographic Emulation 有三种不同模式:
__Remote to Device:__通过使用与 Windows Holographic 设备之间的连接,应用程序就像已经部署到该设备一样,而实际上是在主机上的 Unity Editor 中运行。有关更多信息,请参阅以下的 Emulation Mode:Remote to device 部分。
__Simulate in Editor:__应用程序直接在 Unity Editor 中的模拟 HoloLens 设备上运行,无需连接到真实的 Windows Holographic 设备。有关更多信息,请参阅以下的 Emulation Mode:Simulate in Editor 部分。
__None__:此设置允许仍然在 Editor 中运行应用程序(如果有 Windows Holographic 设备)。
Holographic Emulation 仅在运行 Windows 10(装有 Fall Creators 更新)的机器上受支持。Remote to Device 和 Simulate in Editor 均旨在尽可能模仿当前的 HoloLens 运行时,因此不存在超出此范围的更新 API。这意味着最近添加到输入代码的内容在这些情况下不起作用,就像在 HoloLens 上也不起作用一样。例如,旋转、位置精度、角速度以及用于向前、向上和向右姿势的基础向量全都不存在,因此这些 API 将失败。
要启用远程处理或模拟,请打开 Unity Editor 并选择 Window > XR > Holographic Emulation。
随即将打开 Holographic 控制窗口,其中包含 Emulation Mode 下拉菜单。必须在开发期间保持此窗口可见,这样在启动应用程序时才能访问其设置。
默认情况下,__Emulation Mode__ 设置为 None__,这意味着如果拥有沉浸式头盔连接,应用程序将在 Editor 中运行并在 HMD 上播放。有关更多详细信息,请参阅上文的 Play in Editor__ 部分。
将 Emulation Mode 更改为 Remote to Device 或 Simulate in Editor 可启用 HoloLens 开发的仿真。此设置将为已连接的沉浸式设备覆盖 Play in Editor 支持。
全息远程处理 (Holographic Remoting) 可让应用程序就像已经部署到 HoloLens 设备上一样,而实际是在主机上的 Unity Editor 中运行。即使在远程处理时,来自所连接设备的空间传感器数据和头部跟踪仍然处于激活状态并正常工作。在 Unity Editor Game 视图中可以查看设备上渲染的内容,但不能看到设备的佩戴者看到的真实世界。(请参阅上文中标题为“启用 Holographic Emulation 时的 Unity Editor 运行情况”的图中的示例。)
__注意:__全息远程处理是一种在开发过程中快速迭代更改的方式,但应避免将其用于验证性能。应用程序在主机上而不是在设备本身上运行,因此可能会得到不准确的结果。
要在 Unity Editor 中启用此模式,请将 Emulation Mode 设置为 Remote to Device。然后,Holographic 窗口将更改以反映此模式下可用的其他设置。
要远程连接 HoloLens 设备,必须在 HoloLens 设备上安装 Holographic Remoting Player。
要安装 Holographic Remoting Player 应用程序并配置 Unity Editor,请执行以下操作:
从 HoloLens 应用商店安装并运行 Holographic Remoting Player。可从 Hololens 上的 Windows 应用商店应用程序中获取此应用程序。Remoting Player 在启动时进入等待状态,并在 HoloLens 屏幕上显示设备的 IP 地址:
有关此 Player 的其他信息,包括如何启用连接诊断,请参阅 Microsoft Windows 开发人员中心。
在 Unity Editor 的 Holographic 窗口的 Remote Machine 字段中输入 HoloLens 设备的 IP 地址。使用该字段右侧的下拉选单按钮可选择最近使用的地址:
单击 Connect 按钮。连接状态应会更改为绿灯并显示已连接消息。
单击 Unity Editor 中的 Play 以远程运行设备。
远程处理开始后,即可进行暂停、检查游戏对象以及调试,操作就像在 Editor 中运行任何应用程序一样。HoloLens 设备与主机之间通过网络来回传输视频、音频和设备输入。
对 HoloLens 使用 Remote to Device 仿真时,应考虑以下几个限制:
使用 Remote to Device 仿真模式时,Unity 不支持 Speech (PhraseRecognizer)。在此模式下,模拟器会拦截运行 Unity Editor 的主机发出的语音。应用程序将使用执行远程处理的 PC 中的麦克风,而不是 Hololens 麦克风。
当 Remote to Device 正在运行时,主机上的所有音频都会重定向到设备,包括来自应用程序外部的音频。
使用此仿真模式时,应用程序直接在 Unity Editor 中的模拟全息设备上运行,无需连接到真实的 HoloLens 设备。在进行 Windows Holographic 的开发时,如果无法访问 HoloLens 设备,此模式将非常有用。
__注意:__应在 HoloLens 设备上测试应用程序,确保其能够按预期工作。在开发过程中不要完全依赖仿真。
要启用此模式,请将 Emulation Mode 设置为 Simulate in Editor__,然后单击 Play__ 按钮。然后,应用程序将在 Unity Editor 内置的模拟器中启动。
在 Holographic Emulation 控制窗口中,使用 Room 下拉菜单选择可用的虚拟房间(与 XDE HoloLens 模拟器提供的相同)。使用 Gesture Hand 下拉菜单指定由哪个虚拟手执行手势(左手还是右手)。
在 Simulate in Editor 模式中,需要使用游戏控制器(例如 Xbox 360 或 Xbox One 控制器)来控制虚拟人类玩家。如果没有控制器,模拟仍然有效,但无法移动虚拟人类玩家。
下表列出了 Simulate in Editor 模式期间的控制器输入及其用法。
控制 | 用法 |
---|---|
左摇杆 | 上下方向可使虚拟人类玩家前后移动。左右方向可使人类玩家左右移动。 |
右摇杆 | 上下方向可上下旋转虚拟人类玩家的头部(围绕 X 轴旋转 - 俯仰)。左右方向可左右转动虚拟人类玩家(围绕 Y 轴旋转 - 偏航)。 |
十字方向键 | 上下移动虚拟人类玩家或左右倾斜玩家的头部(围绕 Z 轴旋转 - 翻滚)。 |
左右触发按钮或 A 按钮 | 使用虚拟手执行点击手势。 |
Y 按钮 | 重置虚拟人类玩家头部的俯仰(X 旋转)和翻滚(Z 旋转)。 |
要使用游戏控制器,请将 Unity Editor 聚焦在 Game 视图上。如果当前焦点位于另一个 Unity Editor 窗口,请单击 Game 视图窗口以重新聚焦于 Game 视图。
对 HoloLens 使用 Simulate in Editor 仿真时,应考虑以下几个限制:
大多数游戏控制器都能在 Simulate in Editor 模式下工作,但前提是 Windows 和 Unity 能识别它们。但是,不受支持的控制器可能会导致兼容性问题。
可在 Simulate in Editor 模式期间使用 PhotoCapture,但由于缺少连接的 HoloLens 设备,必须使用外部连接的摄像头(例如网络摄像头)。这种情况下也会导致无法使用 TryGetProjectionMatrix
或 TryGetCameraToWorldMatrix
来检索矩阵,因为普通的外部摄像头无法计算自身与现实世界的相对位置。
在解决 Windows Mixed Reality 应用程序的开发问题时,以下外部资源非常有用:
2018–03–27 页面已发布并进行了编辑审查
在 2017.3 版中添加了关于 XR API 变更的新内容
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.