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. 開啟 [Player 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. 開啟 [Player 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. 您也可以將轉譯 模式 設定為 Custom,以手動方式執行這項作業。然後將 模式 設定為 [透明],最後將 [深度寫入] 設定為 [開啟]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 開發,將相機近和遠的平面修改為較小的範圍,並保留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.)

重要

Unity 在使用16位深度格式時,不會建立樣板緩衝區Unity does not create a stencil buffer when using 16-bit depth format. 因此,某些 Unity UI 效果和其他樣板所需的效果將無法運作,除非選取了24位深度格式,而這會建立 8 位的樣板緩衝區。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.

建立 IL2CPPBuilding for IL2CPP

Unity 已淘汰 .NET 腳本後端的支援,因此建議開發人員使用 IL2CPP 來處理其 UWP visual studio 組建。Unity has deprecated support for the .NET scripting backend and thus recommends that developers utilize IL2CPP for their UWP visual studio builds. 雖然這帶來了各種優點,但從 Unity 建立您的 visual studio 解決方案, IL2CPP 可能會比舊的 .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 None 顯示預設的 Unity 啟動顯示畫面5秒,或直到應用程式載入為止,以較長的時間為准。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 None 在載入應用程式之前,顯示透明的黑色 (沒有任何) 。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 VideoCapture 捕獲音訊) 、DictationRecognizer、GrammarRecognizer 和 KeywordRecognizer 時的 (VideoCapture (when capturing audio), DictationRecognizer, GrammarRecognizer, and KeywordRecognizer
InternetClientInternetClient DictationRecognizer (並使用 Unity Profiler) DictationRecognizer (and to use the Unity Profiler)

請參閱See also