导出和构建 Unity Visual Studio 解决方案Exporting and building a Unity Visual Studio solution

如果你的应用程序不需要系统键盘,我们建议使用 D3D ,使你的应用程序使用略微少的内存和更快的启动时间。If your app doesn't need the system keyboard, our recommendation is to use D3D so that your app uses slightly less memory and a faster launch time. 但是,如果通过 TouchScreenKeyboard API 使用系统键盘,则需要将项目导出为 XAMLHowever, if you're using the system keyboard through the TouchScreenKeyboard API, you need to export the project as XAML.

如何从 Unity 导出How to export from Unity

Unity 生成设置Unity build settings
Unity 编辑器中的生成设置Build settings in Unity editor

  1. 如果已准备好从 Unity 导出项目,请打开 "文件" 菜单,然后选择 "生成设置 ... "When you're ready to export your project from Unity, open the File menu and select Build Settings...
  2. 选择 " 添加打开的场景 ",将场景添加到生成中。Select Add Open Scenes to add your scene to the build.
  3. 在 " 生成设置 " 对话框中,选择以下要为 HoloLens 导出的选项:In the Build Settings dialog, choose the following options to export for HoloLens:
    • 平台: 通用 Windows 平台 ,并确保选择 " 切换平台 " 以使选择生效。Platform: Universal Windows Platform and be sure to select Switch Platform for your selection to take effect.
    • SDK: 通用 10SDK: Universal 10.
    • UWP 生成类型: D3DUWP Build Type: D3D.
  4. 可选Unity c # 项目: 已选中。Optional: Unity C# Projects: Checked.

备注

选中此框后,您可以:Checking this box allows you to:

  • 在 Visual Studio 远程调试器中调试你的应用程序。Debug your app in the Visual Studio remote debugger.
  • 使用 IntelliSense for WinRT Api 时在 Unity c # 项目中编辑脚本。Edit scripts in the Unity C# project while using IntelliSense for WinRT APIs.
  1. 从 "生成设置 ... " 窗口中,打开 "播放机设置 ... "From the Build Settings... window, open Player Settings...
  2. 选择通用 Windows 平台 "选项卡的" 设置 "。Select the Settings for Universal Windows Platform tab.
  3. 展开“XR 设置”组。Expand the XR Settings group.
  4. 在 " XR 设置 " 部分中,选中 " 受支持的虚拟现实 " 复选框,以添加新的 虚拟现实设备 列表,并确认 "Windows Mixed Reality" 列为受支持的设备。In the XR Settings section, check the Virtual Reality Supported checkbox to add a new Virtual Reality Devices list and confirm "Windows Mixed Reality" is listed as a supported device.
  5. 返回到 " 生成设置 " 对话框。Return to the Build Settings dialog.
  6. 选择“生成” 。Select Build.
  7. 在出现的 "Windows 资源管理器" 对话框中,创建一个新文件夹来保存 Unity 的生成输出。In the Windows Explorer dialog that appears, create a new folder to hold Unity's build output. 通常,将文件夹命名为 "App"。Generally, we name the folder "App".
  8. 选择新创建的文件夹,然后选择 " 选择文件夹"。Select the newly created folder and select Select Folder.
  9. Unity 完成生成后,将打开项目根目录的 Windows 资源管理器窗口。Once Unity has finished building, a Windows Explorer window will open to the project root directory. 导航到新创建的文件夹。Navigate into the newly created folder.
  10. 打开位于此文件夹中的生成的 Visual Studio 解决方案文件。Open the generated Visual Studio solution file located inside this folder.

何时从 Unity 重新导出When to re-export from Unity

在从 Unity 导出应用程序时,选中 " c # 项目 " 复选框会创建一个包含所有 Unity 脚本文件的 Visual Studio 解决方案。Checking the C# Projects checkbox when exporting your app from Unity creates a Visual Studio solution that includes all your Unity script files. 让所有脚本都位于同一位置,无需从 Unity 重新导出即可进行迭代。Having all your scripts in one place lets you iterate without re-exporting from Unity. 但是,如果对不只是更改脚本内容的项目进行更改,则需要从 Unity 重新导出。However, if you make changes to your project that aren't just changing the contents of scripts, you'll need to re-export from Unity. 需要从 Unity 重新导出的一些时间示例如下:Some examples of times you need to re-export from Unity are:

  • 您可以在 "项目" 选项卡中添加或删除资产。You add or remove assets in the Project tab.
  • 您可以在 "检查器" 选项卡中更改任何值。You change any value in the Inspector tab.
  • 您可以在 "层次结构" 选项卡中添加或删除对象。You add or remove objects from the Hierarchy tab.
  • 更改任何 Unity 项目设置You change any Unity project settings

生成和部署 Unity Visual Studio 解决方案Building and deploying a Unity Visual Studio solution

Visual Studio中生成和部署应用程序的其余部分。The remainder of building and deploying apps happens in Visual Studio. 你将需要指定 Unity 生成配置。You will need to specify a Unity build configuration. Unity 的命名约定可能不同于你在 Visual Studio 中所用的内容:Unity's naming conventions may differ from what you're used to in Visual Studio:

配置Configuration 说明Explanation
调试Debug 禁用所有优化,并启用探查器。All optimizations off and the profiler is enabled. 用于调试脚本。Used to debug scripts.
MasterMaster 启用所有优化并禁用探查器。All optimizations are turned on and the profiler is disabled. 用于将应用提交到应用商店。Used to submit apps to the Store.
发布Release 启用所有优化,并启用探查器。All optimizations are turned on and the profiler is enabled. 用于评估应用程序性能。Used to evaluate app performance.

请注意,上面的列表是常见触发器的一个子集,将导致需要生成 Visual Studio 项目。Note, the above list is a subset of the common triggers that will cause the Visual Studio project to need to be generated. 通常,在 Visual Studio 中编辑 .cs 文件不需要从 Unity 内重新生成项目。In general, editing .cs files from within Visual Studio won't require the project to be regenerated from within Unity.

疑难解答Troubleshooting

如果你发现在你的 Visual Studio 项目中无法识别对 .cs 文件的编辑,请确保在从 Unity 的 "生成" 菜单生成 VS 项目时检查 Unity c # 项目If you find that edits to your .cs files aren't being recognized in your Visual Studio project, ensure that Unity C# Projects is checked when you generate the VS project from Unity's Build menu.