6.打包并部署到设备或仿真器6. Packaging & deploying to device or emulator

概述Overview

在上一个教程中,你添加了一个简单的按钮,来将象棋棋子重置到原始位置。In the previous tutorial, you added a simple button that resets the chess piece to its original position. 这是最后一个部分,介绍了如何将此应用准备就绪,以在 HoloLens 2 或仿真器中运行它。In this final section, you'll get the app ready to run on a HoloLens 2 or an Emulator. 如果你有 HoloLens 2,则可以从计算机进行流式传输,或者打包应用,以便直接在设备上运行。If you have a HoloLens 2, you can either stream from your computer or package the app to run directly on the device. 如果没有设备,则打包应用,以便在仿真器上运行它。If you don't have a device, you'll be packaging the app to run on the Emulator. 本部分结束时,你将拥有一个已部署的混合现实应用,你可以通过交互和 UI 充分利用它。By the end of this section, you'll have a deployed mixed reality app that you can play, complete with interactions and UI.

目标Objectives

  • [仅设备] 通过全息应用远程处理流式传输到 HoloLens 2[Device only] Streaming to HoloLens 2 with holographic app remoting
  • 打包应用并将其部署到 HoloLens 2 设备或仿真器Packaging and deploying the app to a HoloLens 2 device or emulator

[仅设备] 流式传输[Device Only] Streaming

在这种情况下,全息远程处理是指将数据从电脑或独立 UWP 设备流式传输到 HoloLens 2,而非切换通道。Holographic Remoting in this case means streaming data from a PC or standalone UWP device to the HoloLens 2, not switching the channel. 这种方法的工作方式是,远程处理主机应用从 HoloLens 接收输入数据流,在虚拟沉浸式视图中呈现内容,并通过 Wi-Fi 将内容帧流式传输回 HoloLens。The way this works is a remoting host app receives an input data stream from a HoloLens, renders content in a virtual immersive view, and streams content frames back to HoloLens over Wi-Fi. 通过流式处理,可以将远程沉浸式视图添加到现有的台式电脑软件中,并可访问更多系统资源。Streaming allows you to add remote immersive views into existing desktop PC software and has access to more system resources.

如果要将此方法用于该象棋应用,需要完成以下事项:If you're going this route with the chess app, you'll need a few things:

  1. 在 HoloLens 2 上从 Microsoft Store 安装并运行“全息远程处理播放器”。Install the Holographic Remoting Player from the Microsoft Store on your HoloLens 2 and run the app. 请注意应用中显示的 IP 地址。Note your IP address displayed in the app.

  2. 返回到 Unreal 编辑器,转到“编辑”>“项目设置”,然后选中“全息远程处理”部分中的“启用远程处理” 。Back in the Unreal editor, go to Edit > Project Settings and check Enable Remoting in the Holographic Remoting section.

  3. 重启编辑器,然后输入设备的 IP 地址(如全息远程处理播放器应用中所示),然后单击“连接”。Restart the editor, then enter your device's IP address (as displayed in the Holographic Remoting Player app), then click Connect.

连接后,单击“开始”按钮右侧的下拉箭头,然后选择“VR 预览”。 Once you’re connected, click the drop-down arrow to the right of the Play button and select VR Preview. 此操作将在“VR 预览”窗口中运行应用,该窗口将流式传输到 HoloLens 头戴显示设备。This will run the app in the VR Preview window, which is streamed to the HoloLens headset.

通过设备门户打包和部署应用Packaging and deploying the app via device portal

备注

如果这是你第一次为 HoloLens 打包 Unreal 应用,则需要从 Epic Launcher 下载支持文件。If this is your first time packaging an Unreal app for HoloLens, you'll need to download supporting files from the Epic Launcher.

  • 转到“编辑器首选项”>“常规”>“源代码”>“源代码编辑器”,然后检查是否已选择 Visual Studio 2019。Go to Editor Preferences > General > Source Code > Source Code Editor and check that Visual Studio 2019 is selected.
  • 转到 Epic Games Launcher 的“库”选项卡,选择“启动”旁的下拉箭头,然后单击“选项”。 Go to the Library tab in the Epic Games Launcher, select the dropdown arrow next to Launch >and click Options.
  • 在“目标平台”下,选择“HoloLens 2”,然后单击“应用”。Under Target Platforms, select HoloLens 2 and click Apply. 更改项目设置中的目标平台Change target platform in project settings
  1. 转到“编辑”>“项目设置”。Go to Edit > Project Settings.
    • 在“项目 > 描述 > 关于 > 项目名称”下,添加项目名称。Add a project name under Project > Description > About > Project Name.
    • 在“项目”>“描述”>“发布者”>“公司可分辨名称”下,添加“CN=YourCompanyName” 。Add CN=YourCompanyName under Project > Description > Publisher > Company Distinguished Name.

重要

如果将这些字段中的任一字段留空,那么当你在步骤 3 中尝试生成新证书时将遇到错误。Leaving either of these fields blank will result in an error when you try and generate a new certificate in step 3.

重要

发布者的名称必须采用 LADPv3 可分辨名称格式The publisher's name must be in LADPv3 Distinguished Names Format. 格式不正确的发布者名称会导致在打包时出现“找不到签名密钥。A malformed publisher's name leads to the "Signing key not found. 无法对应用进行数字签名。”The app could not be digitally signed." 错误。error upon packaging.

项目设置 - 描述

  1. 在“平台 > HoloLens”下,启用“为 HoloLens 仿真生成”和/或“为 HoloLens 设备生成”。 Enable Build for HoloLens Emulation and/or Build for HoloLens Device under Platforms > HoloLens.

  2. 单击“打包”部分(在“签名证书”旁)中的“生成新的” 。Click Generate new in the Packaging section (next to Signing Certificate).

重要

如果使用的是已生成的证书,证书的发布者名称则必须与应用程序的发布者名称相同。If you're using an already generated certificate, then the certificate's publisher name must be the same as the application's publisher name. 否则,会导致“找不到签名密钥。Otherwise it leads to the "Signing key not found. 无法对应用进行数字签名。”The app could not be digitally signed." error。error.

项目设置 - 平台 - HoloLens

  1. 当系统提示你创建私钥密码时,出于测试目的,请单击“无”。Click None for testing purposes when you're prompted to create a Private Key Password.

正在生成新证书

  1. 转到“文件”>“包项目”并选择“HoloLens”。Go to File > Package Project and select HoloLens.

    • 创建新文件夹以保存包,并单击“选择文件夹”。Create a new folder to save your package in and click Select Folder.
  2. 打包应用后,请打开 Windows 设备门户,转到“视图 > 应用”,并找到“部署应用”部分。Open the Windows Device Portal once the app is packaged, go to Views > Apps and find the Deploy apps section.

  3. 单击“浏览...”,转到“ChessApp.appxbundle”文件,然后单击“打开”。 Click Browse..., go to your ChessApp.appxbundle file and click Open.

    • 如果这是你第一次在设备上安装应用,请选中“允许我选择框架包”旁的复选框。Check the box next to Allow me to select framework packages if this is the first time you're installing the app on your device.
    • 在下一个对话框中,包含相应的 VCLibs 和 appx 文件(arm64 用于设备,x64 用于仿真器)。 In the next dialogue, include the appropriate VCLibs and appx files (arm64 for device, x64 for emulator). 在保存包的文件夹中,可以从 HoloLens 下找到这些文件。You can find these under HoloLens inside the folder where you saved your package.
  4. 单击“安装” Click Install

    • 现在可以转到“所有应用”,并点击新安装的应用来运行它,或者可以直接从 Windows 设备门户启动应用 。You can now go to All Apps and tap the newly installed app to run it, or you can start the app directly from the Windows Device Portal.

恭喜!Congratulations! 你的 HoloLens 混合现实应用程序已完成,并且可随时运行。Your HoloLens mixed reality application is finished and ready to go. 不过,这不是旅途的尽头。However, this isn't the end of the road. MRTK 有许多独立功能,你可以将其添加到项目中,其中包括空间映射、凝视和语音输入甚至 QR 码。MRTK has lots of standalone features that you can add to your projects, including spatial mapping, gaze and voice input, and even QR codes. 有关这些功能的详细信息,请参阅 Unreal 开发概述More information on these features can be found in the Unreal development overview.

下一个开发检查点Next Development Checkpoint

如果你遵循我们规划的 Unreal 开发检查点历程,则你处于探索 MRTK 核心构建基块的过程之中。If you're following the Unreal development checkpoint journey we've laid out, you're in the midst of exploring the MRTK core building blocks. 从这里,你可以进入下一个构建基块:From here, you can proceed to the next building block:

或跳转到混合现实平台功能和 API:Or jump to Mixed Reality platform capabilities and APIs:

你可以随时返回到 Unreal 开发检查点You can always go back to the Unreal development checkpoints at any time.