配置项目时不使用 MRTKConfiguring your project without MRTK

Windows Mixed Reality (WMR) 是作为 Windows 10 操作系统的一部分引入的 Microsoft 平台。Windows Mixed Reality (WMR) is a Microsoft platform introduced as part of the Windows 10 operating system. WMR 平台使你能够生成在全息和 VR 显示设备上呈现数字内容的应用程序。The WMR platform lets you build applications that render digital content on holographic and VR display devices.

尽管 Microsoft 和社区创建了开源工具,例如 混合现实工具包 (MRTK) 将自动设置 WMR 环境,但许多开发人员希望从根本上构建他们的经验。While Microsoft and the community have created opensource tools such as the Mixed Reality Toolkit (MRTK) that will automatically set up the WMR environment, many developers wish to build their experiences from the ground up. 如果你使用的是 MRTK,则以下文档将演示如何正确设置用于混合现实开发的项目。The following documentation will demonstrate how to properly set up a project for Mixed Reality development whether you are using MRTK or not. 需要更改的设置分为两类:每个项目的设置和每场景设置。The settings you need to change are broken down into two categories: per-project settings and per-scene settings.

备注

你始终可以在以后导入 MRTK,因此,不会产生要首先进行手动路由的损失。You can always import MRTK later on, so there's no penalty for going the manual route first.

如果选择 WMR 手动设置,则需要更改的设置将分为两个类别:每个项目和每场景。If you choose the WMR manual setup, the settings you need to change are broken-down into two categories: per-project and per-scene.

每个项目的设置Per-project settings

如果面向的是 Desktop VR,建议使用默认情况下在新 Unity 项目上选择的 PC 独立平台:If you're targeting Desktop VR, we suggest using the PC Standalone Platform selected by default on a new Unity project:

在 unity 编辑器中打开的 "生成设置" 窗口的屏幕截图,其中突出显示了 Mac & 独立平台

如果面向的是 HoloLens 2,则需要切换到通用 Windows 平台:If you're targeting HoloLens 2, you need to switch to the Universal Windows Platform:

  1. 选择 文件 > 生成设置 ...Select File > Build Settings...
  2. 选择 "平台" 列表中的 "通用 Windows 平台",然后选择 "切换平台"Select Universal Windows Platform in the Platform list and select Switch Platform
  3. 体系结构 设置为 ARM 64Set Architecture to ARM 64
  4. 目标设备 设置为 HoloLensSet Target device to HoloLens
  5. 生成类型 设置为 D3DSet Build Type to D3D
  6. UWP SDK 设置为 安装的最新版本Set UWP SDK to Latest installed
  7. 生成配置 设置为 发布 ,因为调试存在已知的性能问题Set Build configuration to Release because there are known performance issues with Debug

在 unity 编辑器中打开的生成设置窗口的屏幕截图,其中通用 Windows 平台突出显示

设置平台后,需要让 Unity 知道在导出后创建 沉浸式视图 而不是2d 视图。After setting your platform, you need to let Unity know to create an immersive view instead of a 2D view when exported.

对于 XRSDKFor XRSDK

  1. 在 Unity 编辑器中,导航到 "编辑 > 项目设置",然后选择 " XR 插件管理"In the Unity Editor, navigate to Edit > Project settings and select XR Plugin Management

  2. 选择 "安装 XR 插件管理"Select Install XR Plugin Management

在 unity 编辑器中打开的 "项目设置" 窗口的屏幕截图,其中突出显示了 XR 插件管理

  1. 选择 "启动时初始化 XR" 和 " Windows Mixed Reality "Select Initialize XR on Startup and Windows Mixed Reality

在 unity 编辑器中打开的 "项目设置" 窗口的屏幕截图,其中突出显示了 XR 插件管理

  1. 展开 " XR 插件管理" 部分,并选择 " Windows Mixed Reality "Expand the XR Plug-in Management section and select Windows Mixed Reality
  2. 选中所有框并将 深度提交模式 设置为 深度16位Check all boxes and set Depth Submission Mode to Depth 16 Bit

突出显示了 Windows Mixed Reality 部分的 "项目设置" 窗口的屏幕截图已在 unity 编辑器中打开

对于旧版 XRFor Legacy XR

注意

旧版 XR 在 Unity 2019 中已弃用,并已在 Unity 2020 中删除。Legacy XR is deprecated in Unity 2019 and removed in Unity 2020.

  1. 从生成设置中打开 播放机设置 ... 窗口 并展开 XR 设置Open Player Settings... from the Build Settings... window and expand the XR Settings group
  2. 在 " XR 设置 " 部分中,选择 " 支持的虚拟现实 " 以添加虚拟现实设备列表In the XR Settings section, select Virtual Reality Supported to add the Virtual Reality Devices list
  3. 深度格式 设置为 16 位深度 并启用 深度缓冲共享Set Depth Format to 16-bit Depth and enable Depth Buffer Sharing
  4. 立体声渲染模式 设置为 单一传递实例Set Stereo Rendering Mode to Single Pass Instance
  5. 如果要使用全息远程处理,请选择 " 支持 WSA 全息远程处理 "Select WSA Holographic Remoting Supported if you'd like to use Holographic remoting

突出显示了 "播放机设置" 部分的 "项目设置" 窗口的屏幕截图

更新清单Updating the manifest

您的应用程序现在可以处理全息呈现和空间输入。Your app can now handle holographic rendering and spatial input. 但是,你的应用程序需要在其清单中声明相应的功能,才能利用某些功能。However, your app needs to declare the appropriate capabilities in its manifest to take advantage of certain functionality. 可以通过转到 " 播放机设置" > "通用 Windows 平台 >" 发布设置 "> 功能,找到项目功能。You can find your projects capabilities by going to Player Settings > Settings for Universal Windows Platform > Publishing Settings > Capabilities.

建议在 Unity 中创建清单声明,以将其包含在所有以后导出的项目中。It's recommended that you make the manifest declarations in Unity to include them in all future projects that you export. 为混合现实启用常用 Unity Api 的适用功能包括:The applicable capabilities for enabling commonly used Unity APIs for Mixed Reality are:

功能Capability 需要功能的 ApiAPIs requiring capability
SpatialPerceptionSpatialPerception SurfaceObserver (访问 HoloLens 上的 空间映射网格) — 无需对耳机进行常规空间跟踪SurfaceObserver (access to spatial mapping meshes on HoloLens)—No capability needed for general spatial tracking of the headset
网络摄像头WebCam PhotoCapture 和 VideoCapturePhotoCapture and VideoCapture
PicturesLibrary/VideosLibraryPicturesLibrary / VideosLibrary PhotoCapture 或 VideoCapture,分别 (存储捕获的内容) PhotoCapture or VideoCapture, respectively (when storing the captured content)
麦克风Microphone 捕获音频) 、DictationRecognizer、GrammarRecognizer 和 KeywordRecognizer 时的 VideoCapture (VideoCapture (when capturing audio), DictationRecognizer, GrammarRecognizer, and KeywordRecognizer
InternetClientInternetClient DictationRecognizer (并使用 Unity 探查器) DictationRecognizer (and to use the Unity Profiler)

质量设置Quality settings

HoloLens 具有移动类 GPU。HoloLens has a mobile-class GPU. 如果你的应用面向 HoloLens,你需要调整应用中的质量设置以实现最快的性能,以确保它保持完整的帧速率:If your app is targeting HoloLens, you'll want the quality settings in your app tuned for fastest performance to ensure it maintains full frame-rate:

  1. 选择 "编辑 > 项目设置 > 质量"Select Edit > Project Settings > Quality
  2. 选择 Windows 应用商店 徽标下的 下拉列表,并选择 "非常低"。Select the dropdown under the Windows Store logo and select Very Low. 如果 Windows 应用商店列和 极低 的行中的框为绿色,将知道设置正确应用You'll know the setting is applied correctly when the box in the Windows Store column and Very Low row is green
  3. 阴影 部分,选择 "禁用阴影"In the Shadows section, select Disable Shadows

突出显示了 "质量设置" 部分的 "项目设置" 窗口的屏幕截图Screenshot of Project settings window open in unity editor with quality settings section highlighted
Unity 质量设置Unity quality settings

每场景设置Per-scene settings

Unity 照相机设置Unity camera settings

如果选中 " 支持虚拟现实 ",则 Unity 相机 组件会处理 头跟踪和 stereoscopic 呈现With Virtual Reality Supported checked, the Unity Camera component handles head tracking and stereoscopic rendering. 这意味着不需要使用自定义相机替换主相机对象。That means there's no need for you to replace the Main Camera object with a custom camera.

如果你的应用程序专门面向 HoloLens,则需要更改一些设置以优化设备的透明显示。If your app is targeting HoloLens specifically, you need to change a few settings to optimize for the device's transparent displays. 这些设置允许你的全息内容透过物理环境显示:These settings allow your holographic content to show through to the physical world:

  1. 层次结构 中,选择 主相机In the Hierarchy, select the Main Camera
  2. 在 " 检查器 " 面板中,将转换 位置 设置为 0,0,0, 以使用户头部的位置从 Unity 世界原点开始。In the Inspector panel, set the transform position to 0, 0, 0 so the location of the user's head starts at the Unity world origin.
  3. 清除标志 更改为 纯色Change Clear Flags to Solid Color.
  4. 背景 色更改为 RGBA 0,0,0,0Change the Background color to RGBA 0,0,0,0. 在 HoloLens 中,黑色呈现为透明。Black renders as transparent in HoloLens.
  5. 更改 剪辑平面-接近HoloLens 建议 0.85 (米) 。Change Clipping Planes - Near to the HoloLens recommended 0.85 (meters).

在 Unity 编辑器中打开的 "检查器" 选项卡的屏幕截图Screenshot of the inspector tab open in the Unity editor
Unity 照相机设置Unity camera settings

重要

如果删除并创建新相机,请确保将新相机标记为 " MainCamera"。If you delete and create a new camera, make sure your new camera is tagged as MainCamera.

后续步骤Next steps

现在,你的项目已准备就绪,可以开始开发混合现实体验:Now that your project is ready, you can start developing your Mixed Reality experience:

另请参阅See also