3.配置 MRTK 配置文件3. Configuring the MRTK profiles

在本教程中,你将学习如何自定义和配置 MRTK 配置文件。In this tutorial, you will learn how to customize and configure the MRTK profiles.

MRTK 配置文件是一个嵌套配置文件树,它们构成了应如何初始化 MRTK 系统和功能的配置信息。The MRTK profiles is a tree of nested profiles that make up the configuration information for how the MRTK systems and features should be initialized. 顶级配置文件(即“配置”配置文件)包含每个主要核心系统的嵌套配置文件。The top-level profile, the Configuration Profile, contains nested profiles for each of the primary core systems. 每个嵌套的配置文件都设计为配置其对应系统的行为。Each nested profile is designed to configure the behavior of their corresponding system.

此特定示例将演示如何通过更改空间网格观察程序的设置来隐藏空间感知网格。This particular example will show you how to hide the spatial awareness mesh by changing the settings of the Spatial Mesh Observer. 但是,可以按照相同的原则来自定义 MRTK 配置文件中的任何设置或值。However, you may follow these same principles to customize any setting or value in the MRTK profiles.

正如你在上一教程期间将项目部署到 HoloLens 2 时遇到的一样,空间感知网格是一系列表示环境几何图形的网格。As you experienced when you deployed your project to your HoloLens 2 during the previous tutorial, the Spatial Awareness mesh is a collection of meshes representing the geometry of the environment. 这是一种有用的可视化效果,一开始就能看到,但通常也可将它关闭,以避免用它后产生视觉干扰和额外的性能影响。It's a helpful visualization to see initially but it's typically turned off to avoid the visual distraction and the additional performance hit of having it on.

目标Objectives

  • 了解如何自定义和配置 MRTK 配置文件Learn how to customize and configure MRTK profiles
  • 隐藏空间感知网格Hide the spatial awareness mesh

更改空间感知显示选项Changing the Spatial Awareness Display Option

隐藏空间感知网格所要执行的主要步骤如下:The main steps you will take to hide the spatial awareness mesh are:

  1. 克隆默认的配置配置文件Clone the default Configuration Profile
  2. 启用空间感知系统Enable the Spatial Awareness System
  3. 克隆默认的空间感知系统配置文件Clone the default Spatial Awareness System Profile
  4. 克隆默认的空间感知网格观察程序配置文件Clone the default Spatial Awareness Mesh Observer Profile
  5. 更改空间感知网格的可见性Change the visibility of the spatial awareness mesh

备注

默认情况下,MRTK 配置文件不可编辑。By default, the MRTK profiles are not editable. 这是一些默认的配置文件模板,必须先克隆它们,然后才能对其进行编辑。These are default profile templates that you have to clone before they can be edited. 配置文件有多个嵌套层。There are several nested layers of profiles. 因此,在配置一个或多个设置时,常见的做法是克隆然后编辑多个配置文件。Therefore, it is common to clone and edit several profiles when configuring one or more settings.

1.克隆默认的配置配置文件1. Clone the default Configuration Profile

备注

配置配置文件是顶级配置文件。The Configuration Profile is the top-level profile. 因此,若要编辑任何其他配置文件,必须先克隆配置配置文件。Consequently, to be able to edit any other profiles, you first have to clone the Configuration Profile.

在“层次结构”窗口中,选择 MixedRealityToolkit 对象,然后在检查器窗口中将“MixedRealityToolkit”配置配置文件更改为“DefaultHoloLens2ConfigurationProfile”:In the Hierarchy window, select the MixedRealityToolkit object, then in the Inspector window, change the MixedRealityToolkit Configuration Profile to the DefaultHoloLens2ConfigurationProfile:

选中 DefaultHoloLens2ConfigurationProfile 的 Unity MixedRealityToolkit 组件

在仍选中了“MixedRealityToolkit”对象的情况下,在检查器窗口中单击“复制和自定义”按钮打开“克隆配置文件”窗口: With the MixedRealityToolkit object still selected, in the Inspector window, click the Copy & Customize button to open the Clone Profile window:

Unity MixedRealityToolkit 组件的“复制和自定义”按钮

在“克隆配置文件”窗口中,输入合适的配置文件名(例如 GettingStarted_HoloLens2ConfigurationProfile),然后单击“克隆”按钮,创建“DefaultHololens2ConfigurationProfile”的可编辑副本 :In the Clone Profile window, enter a suitable Profile Name, for example, GettingStarted_HoloLens2ConfigurationProfile, then click the Clone button to create an editable copy of the DefaultHololens2ConfigurationProfile:

Unity MixedRealityToolkit 的“克隆配置文件”弹出窗口

新建的配置配置文件现已分配为场景中的配置配置文件:The newly created Configuration Profile is now assigned as the Configuration Profile for your scene:

应用了新创建的自定义 HoloLens2ConfigurationProfile 的 Unity MixedRealityToolkit 组件

在 Unity 菜单中,选择“文件” > “保存”以保存场景。 In the Unity menu, select File > Save to save your scene.

提示

在学习整篇教程的过程中,请记得保存自己的工作。Remember to save your work throughout the tutorials.

2.启用空间感知系统2. Enable the Spatial Awareness System

在“层次结构”窗口中,选择 MixedRealityToolkit 对象,接下来在检查器窗口中,选择“空间感知”选项卡,然后选中“启用空间感知系统”复选框: In the Hierarchy window, select the MixedRealityToolkit object, then in the Inspector window, select the Spatial Awareness tab, and then check the Enable Spatial Awareness System checkbox:

启用了空间感知系统的 Unity MixedRealityToolkit 组件

备注

在未来的项目中,如果你的应用无需响应环境或与环境交互,则建议关闭空间感知来减少性能成本。For future projects, if your app doesn't need to respond to or interact with the environment, it's recommended to keep the spatial awareness turned off to reduce performance cost.

3.克隆默认的空间感知系统配置文件3. Clone the default Spatial Awareness System Profile

在“空间感知”选项卡中,单击“克隆”按钮打开“克隆配置文件”窗口: In the Spatial Awareness tab, click the Clone button to open the Clone Profile window:

选中“空间感知”选项卡的 Unity MixedRealityToolkit 组件

在“克隆配置文件”窗口中,输入合适的配置文件名(例如 GettingStarted_MixedRealitySpatialAwarenessSystemProfile),然后单击“克隆”按钮,创建“DefaultMixedRealitySpatialAwarenessSystemProfile”的可编辑副本 :In the Clone Profile window, enter a suitable Profile Name, for example, GettingStarted_MixedRealitySpatialAwarenessSystemProfile, then click the Clone button to create an editable copy of the DefaultMixedRealitySpatialAwarenessSystemProfile:

Unity MixedRealityToolkit 的“克隆空间感知系统配置文件”弹出窗口

新建的空间感知系统配置文件现已自动分配到你的配置配置文件:The newly created Spatial Awareness System Profile is now automatically assigned to your Configuration Profile:

应用了新创建的自定义 MixedRealitySpatialAwarenessSystemProfile 的 Unity MixedRealityToolkit 组件

4.克隆默认的空间感知网格观察程序配置文件4. Clone the default Spatial Awareness Mesh Observer Profile

在仍然选中了“空间感知”选项卡的情况下,展开“Windows Mixed Reality 空间网格观察程序”部分,然后单击“克隆”按钮打开“克隆配置文件”窗口: With the Spatial Awareness tab still selected, expand the Windows Mixed Reality Spatial Mesh Observer section, then click the Clone button to open the Clone Profile window:

已展开“Windows Mixed Reality 空间网格观察程序”部分的 Unity MixedRealityToolkit 组件

在“克隆配置文件”窗口中,输入合适的配置文件名(例如 GettingStarted_MixedRealitySpatialAwarenessMeshObserverProfile),然后单击“克隆”按钮,创建“DefaultMixedRealitySpatialAwarenessMeshObserverProfile”的可编辑副本 :In the Clone Profile window, enter a suitable Profile Name, for example, GettingStarted_MixedRealitySpatialAwarenessMeshObserverProfile, then click the Clone button to create an editable copy of the DefaultMixedRealitySpatialAwarenessMeshObserverProfile:

Unity MixedRealityToolkit 的“克隆空间网格观察程序配置文件”弹出窗口

新建的空间感知网格观察程序配置文件现已自动分配到你的空间感知系统配置文件:The newly created Spatial Awareness Mesh Observer Profile is now automatically assigned to your Spatial Awareness System Profile:

应用了新创建的自定义 MixedRealitySpatialAwarenessMeshObserverProfile 的 Unity MixedRealityToolkit 组件

5.更改空间感知网格的可见性5. Change the visibility of the spatial awareness mesh

在“空间网格观察程序设置”中,将“显示选项”更改为“遮挡”,使空间映射网格在隐藏状态下正常运行: In the Spatial Mesh Observer Settings, change the Display Option to Occlusion to make the spatial mapping mesh invisible while still functional:

空间网格观察程序显示选项设置为“遮挡”的 Unity MixedRealityToolkit 组件

备注

尽管空间映射网格不可见,但它依然存在且可正常运行。Although the spatial mapping mesh is not visible, it is still present and functional. 例如,空间映射网格后面的任何全息影像(如真实墙壁后面的全息影像)将不可见。For example, any holograms behind the spatial mapping mesh, such as a hologram behind a physical wall, will not be visible.

你已了解如何修改 MRTK 配置文件中的设置。You just learned how to modify a setting in the MRTK profile. 可以看到,若要自定义 MRTK 设置,首先需要创建默认配置文件的副本。As you can see, to customize the MRTK settings, you first need to create copies of the default profiles. 由于默认配置文件不可编辑,因此,应始终保留这些配置文件,以便在还原为默认设置时参考。Because the default profiles are not editable, you will always have them as references if you want to revert to the default settings. 若要详细了解 MRTK 配置文件及其体系结构,可参阅 MRTK 文档门户中的 MRTK 配置文件配置指南To learn more about MRTK profiles and their architecture, you can refer to the MRTK profile configuration guide in the MRTK Documentation Portal.

祝贺Congratulations

在本教程中,你学习了如何克隆、自定义和配置 MRTK 配置文件和设置。In this tutorial, you learned how to clone, customize, and configure MRTK profiles and settings.