建议用于 Unity 的设置Recommended settings for Unity

Unity 提供了一组默认选项,这些选项通常是所有平台的平均事例。Unity provides a set of default options that are generally the average case for all platforms. 但是,Unity 提供一些特定于混合现实的行为,这些行为可通过项目设置进行切换。However, Unity offers some behaviors specific to mixed reality that can be toggled through project settings.

设置高性能环境Performant environment set-up

低质量设置Low-quality settings

很重要的一点是,将 Unity 质量设置 修改为 非常低 ,以使应用程序正常运行并在适当的帧速率下执行,特别是对于 HoloLens 开发。It's important to modify the Unity Quality settings to Very Low so that your application is runs and performs well at the appropriate framerate, especially for HoloLens development. 若要在沉浸式耳机上进行开发,根据桌面的规格来支持 VR 体验,仍可在没有最低质量参数的情况下实现帧速率。For development on immersive headsets, depending on the specs of the desktop powering the VR experience, one can still achieve framerate without the lowest quality parameters.

在 Unity 2019 LTS + 中,您可以通过转到 编辑 > 项目设置 > 质量 并通过单击向下箭头到 * * 非常低质量级别设置 默认值,来设置项目的质量级别。In Unity 2019 LTS+, you can set the project's quality level by going to Edit > Project Settings > Quality and setting the Default by clicking on the downward arrow to the **Very Low-quality level.

照明设置Lighting settings

与质量场景设置相似,必须为混合现实应用程序设置最佳照明设置。Similar to Quality scene settings, it's important to set optimal Lighting settings for your Mixed Reality application. 在 Unity 中,通常会对场景产生最大性能影响的照明设置是 实时全局照明In Unity, the Lighting setting that will usually have the greatest performance impact on your scene is Realtime Global Illumination. 您可以通过转到 窗口 > 渲染 > 照明设置 > 实时全局照明 来关闭全局照明。You can turn off Global Illumination by going to Window > Rendering > Lighting Settings > Realtime Global Illumination.

还有另一个照明设置, 融入全局照明There's another lighting setting, Baked Global Illumination. 此设置可以提供沉浸式耳机上的高性能和视觉效果,但不适用于 HoloLens 开发。This setting can provide performant and visually striking results on immersive headsets but isn't applicable for HoloLens development. 融入全局照明 仅针对静态 gameobject 进行计算,这种情况是由于未知和不断变化的环境的性质而在 HoloLens 场景中找不到的。Baked Global Illumination is only calculated for static GameObjects, which aren't found in HoloLens scenes because of the nature of an unknown and changing environment.

有关详细信息,请参阅 Unity 的全局照明Read Global Illumination from Unity for more information.

备注

实时全局照明根据场景 设置的,因此,开发人员必须为其项目中的每个 Unity 场景保存此属性。Realtime Global Illumination is set per-scene and thus developers must save this property for every Unity scene in their project.

单步实例呈现路径Single pass instancing rendering path

在混合现实应用程序中,场景呈现两次,一次为用户提供一次。In Mixed Reality applications, the scene is rendered twice, once for each eye to the user. 与传统的3D 开发相比,这实际上会使需要计算的工作量加倍。Compared to traditional 3D development, this effectively doubles the amount of work that needs to be computed. 在 Unity 中选择最有效的呈现路径,以节省 CPU 和 GPU 时间,这一点很重要。It's important to select the most efficient rendering path in Unity to save both on CPU and GPU time. 单个传递实例呈现为混合现实应用优化了 Unity 呈现管道,建议为每个项目默认启用此设置。Single pass instanced rendering optimizes the Unity rendering pipeline for Mixed Reality apps and it's recommended to enable this setting by default for every project.

在 Unity 项目中启用此功能To enable this feature in your Unity Project

  1. 打开“播放器 XR 设置”(转到“编辑” > “项目设置” > “播放器” > “XR 设置”) Open Player XR Settings (go to Edit > Project Settings > Player > XR Settings)
  2. 从“立体渲染方法”下拉菜单中选择“单通道实例化”(必须选中“支持虚拟现实”复选框) Select Single Pass Instanced from the Stereo Rendering Method drop-down menu (Virtual Reality Supported checkbox must be checked)

有关此呈现方法的更多详细信息,请参阅 Unity 中的以下文章。Read the following articles from Unity for more details with this rendering approach.

备注

如果开发人员的现有自定义着色器不是针对实例化编写的,则单通道实例化渲染会发生一个常见问题。One common issue with Single Pass Instanced Rendering occurs if developers already have existing custom shaders not written for instancing. 启用此功能后,开发人员可能会注意到,某些 GameObject 只在一只眼睛中呈现。After enabling this feature, developers may notice some GameObjects only render in one eye. 这是因为,关联的自定义着色器没有与实例化相关的适当属性。This is because the associated custom shaders do not have the appropriate properties for instancing.

请参阅 Unity 文章 HoloLens 的 单通道立体渲染来了解如何解决此问题See Single Pass Stereo Rendering for HoloLens from Unity for how to address this problem

启用深度缓冲共享Enable depth buffer sharing

若要从用户的感觉获得更好的全息图稳定性,建议启用 Unity 中的 深度缓冲区共享 属性。To achieve better hologram stability from the perception of the user, it's recommended to enable the Depth Buffer Sharing property in Unity. 通过启用,Unity 将使用 Windows Mixed Reality 平台共享你的应用程序生成的深度映射。By turning this on, Unity will share the depth map produced by your application with the Windows Mixed Reality platform. 然后,该平台可以更好地针对应用程序呈现的任何给定帧,更好地为场景优化全息图稳定性。The platform can then better optimize hologram stability specifically for your scene for any given frame being rendered by your application.

在 Unity 项目中启用此功能To enable this feature in your Unity Project

  1. 打开“播放器 XR 设置”(转到“编辑” > “项目设置” > “播放器” > “XR 设置”) Open Player XR Settings (go to Edit > Project Settings > Player > XR Settings)
  2. 选中 "在 虚拟现实 sdk启用深度缓冲区共享" 复选框 > Windows Mixed Reality (必须选中 "支持虚拟现实" 复选框) Select the checkbox for Enable Depth Buffer Sharing under Virtual Reality SDKs > Windows Mixed Reality expansion (Virtual Reality Supported checkbox must be checked)

此外,建议在此面板中的 "深度格式" 设置下选择 " 16 位深度",尤其是对于 HoloLens 开发。Further, it's recommended to select 16-bit depth under the Depth Format setting in this panel, especially for HoloLens Development. 与24位相比,选择16位可显著减少带宽需求,因为需要移动/处理的数据量较少。Selecting 16-bit compared to 24-bit will significantly reduce the bandwidth requirements as less data will need to be moved/processed.

为了使 Windows Mixed Reality 平台优化全息影像稳定性,它依赖于深度缓冲区来精确并匹配屏幕上呈现的所有全息影像。In order for the Windows Mixed Reality platform to optimize hologram stability, it relies on the depth buffer to be accurate and match any rendered holograms on screen. 因此,在上进行深度缓冲共享时,在呈现颜色时,这一点非常重要,也就是呈现深度。Thus, with depth buffer sharing on, it is important when rendering color, to also render depth. 在 Unity 中,大多数不透明或 TransparentCutout 的材料默认呈现深度,但透明和文本对象将不会呈现深度,尽管这与着色器相关,等等。In Unity, most Opaque or TransparentCutout materials will render depth by default but transparent and text objects will not render depth although this is shader-dependent, etc.

如果使用 混合现实工具包标准着色器来呈现透明对象的深度:If using the Mixed Reality Toolkit Standard shader, to render depth for transparent objects:

  1. 选择使用 MRTK 标准着色器的透明材料,并打开检查器编辑器窗口Select the transparent material that is using the MRTK Standard shader and open the Inspector editor window
  2. 选择深度缓冲区共享警告中的 " 立即修复 " 按钮。Select the Fix Now button within the depth buffer sharing warning. 也可以通过将 呈现模式 设置为 " 自定义" 来手动执行此方法。然后将 模式 设置为 透明 ,最后将 " 深度写入 " 设置为 "开"This can also be performed manually by setting the Rendering Mode to Custom; then set Mode to Transparent and finally set Depth Write to On

重要

在更改这些值时,开发人员应注意 Z 反击,同时还应注意相机的近/远平面设置。Developers should beware of Z-fighting when changing these values along with the camera's near/far plane settings. 当两个 gameobject 尝试呈现到同一个像素,并由于深度缓冲区的保真度限制而产生了 Z 反击 (即Z-Fighting occurs when two gameobjects try to render to the same pixel and due to limitations in fidelity of the depth buffer (i.e z 深度) 中,Unity 无法识别哪个对象位于另一个对象之前。z depth), Unity cannot discern which object is in front of the other. 开发人员将注意两个游戏对象之间的闪烁,因为它们会 抵抗 相同的 z 深度值。Developers will note a flickering between two game objects as they fight for the same z-depth value. 这可以通过切换到24位深度格式来解决,因为每个对象的值的范围都要根据其 z 深度从相机计算。This can be solved by switching to 24-bit depth format as there will be a larger range of values for each object to calculate upon for their z-depth from the camera.

不过,建议使用此方法,特别是在 HoloLens 开发环境中,可以改为将相机的近处和 far 面修改为较小的范围,并保留16位的深度格式。However, it is recommended, particularly for HoloLens development, to modify the camera's near and far planes to a smaller range instead and retain the 16-bit depth format. Z 深度以非线性方式映射到沿近和远相机平面的值范围。The z-depth is non-linearly mapped to the range of values along the near and far camera planes. (若要修改此项 & ,可选择场景中的 主相机,然后在 "检查器"This can be modified by selecting the Main Camera in your scene and under Inspector, change the Near & Far Clipping Plane values to reduce their range (i.e 从1000m 到100m 或其他 x 值等 ) from 1000m to 100m or other x value, etc.)

重要

使用16位深度格式时, Unity 不会创建模具缓冲区Unity does not create a stencil buffer when using 16-bit depth format. 因此,除非选择了将创建 8 位模具缓冲区的24位深度格式,否则某些 Unity UI 效果和其他模具所需的效果将无法工作。Thus, some Unity UI effects and other stencil-required effects will not work unless 24-bit depth format is selected which will create an 8-bit stencil buffer.

为 IL2CPP 生成Building for IL2CPP

Unity 已弃用 .NET 脚本编写后端的支持,因此建议开发人员使用 IL2CPP 来实现 UWP visual studio build。Unity has deprecated support for the .NET scripting backend and thus recommends that developers utilize IL2CPP for their UWP visual studio builds. 虽然这带来了各种优势,但从 Unity for IL2CPP 构建 visual studio 解决方案可能比旧的 .net 方法要慢。Although this brings various advantages, building your visual studio solution from Unity for IL2CPP can be slower than the old .NET method. 因此,强烈建议遵循用于生成 IL2CPP 的最佳做法,以便在开发迭代时节省时间。Thus, it is highly recommended to follow best practices for building IL2CPP to save on development iteration time.

  1. 使用增量生成,每次将项目生成到同一个目录,并在此处重复使用预先生成的文件Leverage incremental building by building your project to the same directory every time, reusing the pre-built files there
  2. 禁用项目 & 生成文件夹的反恶意软件扫描Disable anti-malware software scans for your project & build folders
    • 在 Windows 10 设置应用下打开 病毒 & 威胁防护Open Virus & threat protection under your Windows 10 settings app
    • 选择 "安全 & 威胁防护设置" 下的 "管理设置"Select Manage Settings under Virus & threat protection settings
    • 选择 "排除" 部分下的 "添加或删除排除 项"Select Add or remove exclusions under the Exclusions section
    • 选择 " 添加排除 ",然后选择包含 Unity 项目代码和生成输出的文件夹Select Add an exclusion and select the folder containing your Unity project code and build outputs
  3. 使用 SSD 进行生成Use an SSD for building

有关详细信息,请阅读 优化 IL2CPP 的生成时间Read Optimizing Build Times for IL2CPP for more info.

备注

此外,设置缓存服务器可能会有所帮助,尤其是对于包含大量资产(不包括脚本文件)或不断变化的场景/资产的 Unity 项目而言。Furthermore, it may be beneficial to setup a Cache Server, especially for Unity projects with a large amount of assets (excluding script files) or constantly changing scenes/assets. 打开项目时,Unity 会在开发人员计算机上将符合条件的资产存储为内部缓存格式。When opening a project, Unity stores qualifying assets into an internal cache format on the developer machine. 必须重新导入项,因此,项在修改后会重新经过处理。Items must be re-imported and thus re-processed when modified. 此过程可以执行一次,结果可保存在缓存服务器,因此可与其他开发人员共享以节省时间,无需让每个开发人员在本地重新导入新的更改。This process can be done once and saved in a Cache Server and consequently shared with other developers to save time, instead of every developer processing the re-import of new changes locally.

发布属性Publishing properties

全息初始屏幕Holographic splash screen

HoloLens 具有移动类 CPU 和 GPU,这意味着可能需要更长的时间来加载应用。HoloLens has a mobile-class CPU and GPU, which means apps may take a bit longer to load. 在应用程序加载时,用户只会看到黑色,因此他们可能会想知道发生了什么情况。While the app is loading, users will just see black, and so they may wonder what's going on. 若要在加载过程中再次向它们,可添加全息初始屏幕。To reassure them during loading, you can add a holographic splash screen.

若要切换全息初始屏幕:To toggle the holographic splash screen:

  1. 中转到 "编辑 > 项目设置 > 播放器" 页面Go to Edit > Project Settings > Player page
  2. 选择 " Windows 应用商店 " 选项卡,并打开 " 初始图像 " 部分Select the Windows Store tab and open the Splash Image section
  3. Windows 全息 > 全息闪屏映像 属性下应用映像。Apply your image under the Windows Holographic > Holographic Splash Image property.
    • 切换 " 显示 Unity 初始屏幕 " 选项将启用或禁用 Unity 品牌初始屏幕。Toggling the Show Unity Splash Screen option will enable or disable the Unity branded splash screen. 如果没有 Unity Pro 许可证,则将始终显示 Unity 品牌初始屏幕。If you don't have a Unity Pro license, the Unity branded splash screen will always be displayed.
    • 如果应用了 全息初始映像 ,则无论是启用还是禁用 "显示 Unity 初始屏幕" 复选框,它都将始终显示。If a Holographic Splash Image is applied, it will always be displayed whether the Show Unity Splash Screen checkbox is enabled or disabled. 只有具有 Unity Pro 许可证的开发人员才能指定自定义全息启动映像。Specifying a custom holographic splash image is only available to developers with a Unity Pro license.
显示 Unity 初始屏幕Show Unity Splash Screen 全息闪屏映像Holographic Splash Image 行为Behavior
On NoneNone 显示5秒的默认 Unity 初始屏幕或在加载应用之前,以较长者为准。Show default Unity splash screen for 5 seconds or until the app is loaded, whichever is longer.
On 自定义Custom 显示自定义初始屏幕5秒或在加载应用之前,以较长者为准。Show Custom splash screen for 5 seconds or until the app is loaded, whichever is longer.
Off NoneNone 显示透明的黑色 (没有) ,直到加载应用。Show transparent black (nothing) until app is loaded.
Off 自定义Custom 显示自定义初始屏幕5秒或在加载应用之前,以较长者为准。Show Custom splash screen for 5 seconds or until the app is loaded, whichever is longer.

有关详细信息,请阅读 Unity 初始屏幕文档Read Unity's Splash Screen documentation for more info.

失跟Tracking loss

混合现实耳机依赖于查看它周围的环境,以构建 全球锁定的坐标系,使全息影像保持在位置。A Mixed reality headset depends on seeing the environment around it to construct world-locked coordinate systems, which allow holograms to remain in position. 当耳机无法在世界各地定位时,耳机被称为 丢失跟踪When the headset is unable to locate itself in the world, the headset is said to have lost tracking. 在这些情况下,依赖于全球锁定坐标系的功能(如空间阶段、空间锚和空间映射)不起作用。In these cases, functionality dependent on world-locked coordinate systems, such as spatial stages, spatial anchors and spatial mapping, don't work.

如果发生跟踪丢失,则 Unity 的默认行为是停止渲染全息影像,暂停 游戏循环,并显示一条跟踪丢失的通知,以使用户看起来更舒适。If a loss of tracking occurs, Unity's default behavior is to stop rendering holograms, pause the game loop, and display a tracking lost notification that comfortably follows the users gaze. 还可以以跟踪丢失图像的形式提供自定义通知。Custom notifications can also be provided in the form of a tracking loss image. 对于依赖于整个体验的跟踪的应用,足以让 Unity 完全处理此过程,直到重新获得跟踪。For apps that depend upon tracking for their whole experience, it's sufficient to let Unity handle this entirely until tracking is regained. 开发人员可以在跟踪丢失期间提供要显示的自定义图像。Developers can supply a custom image to be shown during tracking loss.

自定义跟踪丢失映像:To customize the tracking lost image:

  1. 中转到 "编辑 > 项目设置 > 播放器" 页面Go to Edit > Project Settings > Player page
  2. 在 " Windows 应用商店 " 选项卡上选择并打开 " 初始图像 " 部分Select on the Windows Store tab and open the Splash Image section
  3. 应用 " Windows 全息 > 跟踪丢失映像 " 属性下的映像。Apply your image under the Windows Holographic > Tracking Loss Image property.

选择退出自动暂停Opt-out of automatic pause

某些应用可能不需要跟踪 (例如, 仅面向打印的应用 (如360度视频查看器)) 或者可能需要在跟踪丢失时继续处理。Some apps may not require tracking (e.g. orientation-only apps such as 360-degree video viewers) or may need to continue processing uninterrupted while tracking is lost. 您可以选择禁用跟踪行为的默认丢失,但您需要负责隐藏/禁用任何对象,这在跟踪丢失方案中无法正确呈现。You can opt out of the default loss of tracking behavior but you're responsible for hiding/disabling any objects, which wouldn't render properly in a tracking-loss scenario. 在大多数情况下,建议在这种情况下呈现的内容只是正文锁定的内容,并在主相机周围居中。In most cases, the only content that is recommended to be render in that case is body-locked content, centered around the main camera.

选择退出自动暂停行为:To opt out of automatic pause behavior:

  1. 请参阅 编辑 > 项目设置 > 播放器 页面Go to the Edit > Project Settings > Player page
  2. 选择 " Windows 应用商店 " 选项卡,并打开 " 初始图像 " 部分Select the Windows Store tab and open the Splash Image section
  3. 修改 " 跟踪丢失时暂停" 和 "显示图像 " 复选框中的 Windows 全息 >。Modify the Windows Holographic > On Tracking Loss Pause and Show Image checkbox.

跟踪丢失事件Tracking loss events

若要在跟踪丢失时定义自定义行为,请处理全局 跟踪丢失事件To define custom behavior when tracking is lost, handle the global tracking loss events.

功能Capabilities

为了使应用程序能够利用特定功能,它必须在其清单中声明相应的功能。For an app to take advantage of certain functionality, it must declare the appropriate capabilities in its manifest. 清单声明可以在 Unity 中进行,因此它们包含在以后的每个项目导出中。The manifest declarations can be made in Unity so they're included in every future project export.

可以通过以下方式为混合现实应用程序启用功能:Capabilities can be enabled for a Mixed Reality application by:

  1. 中转到 "编辑 > 项目设置 > 播放器" 页面Go to Edit > Project Settings > Player page
  2. 选择 " Windows 应用商店 " 选项卡,打开 " 发布设置 " 部分,并查找 功能 列表Select the Windows Store tab, open the Publishing Settings section, and look for the Capabilities list

为全息应用启用常用 Api 的适用功能包括:The applicable capabilities for enabling the commonly used APIs for Holographic apps are:

功能Capability 需要功能的 ApiAPIs requiring capability
SpatialPerceptionSpatialPerception SurfaceObserverSurfaceObserver
网络摄像头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)

另请参阅See also