在沒有 MRTK 的情況下設定專案Configuring 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 專案上使用預設選取的電腦獨立平臺: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. 組建 設定設為 發行 ,因為 Debug 有已知的效能問題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.


  1. 在 Unity 編輯器中,流覽至 [編輯 > 專案設定],然後選取 [ XR 外掛程式管理]In the Unity Editor, navigate to Edit > Project settings and select XR Plugin Management

  2. 選取 [安裝 XR 外掛程式管理]Select Install XR Plugin Management

醒目提示 XR 外掛程式管理的 unity 編輯器中開啟之 [專案設定] 視窗的螢幕擷取畫面

  1. 選取 [ 啟動時初始化 XR ] 和 Windows Mixed RealitySelect Initialize XR on Startup and Windows Mixed Reality

醒目提示 XR 外掛程式管理的 unity 編輯器中開啟之 [專案設定] 視窗的螢幕擷取畫面

  1. 展開 [ XR 外掛程式管理] 區段,然後選取 Windows Mixed RealityExpand 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

在 unity 編輯器中開啟的 [專案設定] 視窗的螢幕擷取畫面,其中已醒目提示 Windows Mixed Reality 區段

針對舊版 XRFor Legacy XR


Unity 2019 中的舊版 XR 已被取代,並已在 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

醒目提示 [播放程式設定] 區段的 [在 unity 編輯器中開啟專案設定] 視窗的螢幕擷取畫面

更新資訊清單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 VideoCapture 捕獲音訊) 、DictationRecognizer、GrammarRecognizer 和 KeywordRecognizer 時的 (VideoCapture (when capturing audio), DictationRecognizer, GrammarRecognizer, and KeywordRecognizer
InternetClientInternetClient DictationRecognizer (並使用 Unity Profiler) 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 Store ] 標誌底下的 下拉式清單,然後選取 [非常低]。Select the dropdown under the Windows Store logo and select Very Low. 您會知道當 Windows Store 資料行中的方塊和 非常低 的資料列中的方塊為綠色時,會正確套用設定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

醒目提示 [品質設定] 區段的 unity 編輯器中開啟的 [專案設定] 視窗螢幕擷取畫面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 world 來源。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


如果您刪除並建立新的相機,請確定您的新相機已標記為 MainCameraIf 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