轉自http://www.cnblogs.com/donghua/p/4957415.html
Oculus/GearVR開發者群 302294234
Welcometo the Unity Development Guide
Introduction簡介
Welcometo the Oculus Unity Developer Guide.
歡迎來到OculusUnity開發者指南。
Thisdocument describes developing Unity 3D games and applications for VR deviceswith the Oculus PC and mobile SDKs. A Unity integration package, sample Unityapplications, and mobile SDK Unity examples are available for PC and mobiledevelopment to help you create virtual reality applications in Unity.
本文檔描述了如何在使用Oculus PC及移動端SDK為VR設備開發U3d游戲及應用。我們提供了Unity整合包、Unity應用實例,以及移動SDK Unity實例來為PC及移動端開發工作提供幫助,幫助你在Unity中創造VR應用。
Thisguide covers:?
Getting started?
Downloading and installing the Oculus Unity integration?
Contents of the integration package?
Howto use the provided samples, assets, and sample applications?
Configuring Unity VR projects for build to various targets
本指南包括的內容有:
? 如何開始?
下載并安裝OculusUnity整合包?
整合包中的內容?
如何使用當中的實例、組件以及實例應用?
怎樣對應多平臺的生成方式
ThisUnity Integration is available for use with the PC development environment forthe Oculus Rift. It is also bundled with the mobile SDK for Samsung Gear VR.Both Unity integrations are capable of building targets for PC or Android.However, keep in mind that the requirements and optimizations for PC and mobileVR applications differ substantially. If you would like to generate builds forboth PC and mobile from a single project, it is important to follow the morestringent mobile development best practices.
本次的Unity整合包可以用來在PC上針對OculusRift的開發環境下使用,同時也可以隨著三星Gear VR的移動SDK一起使用。另外整合包可以同時應對PC和安卓的兩種生成方式。不過需要注意的是,PC與移動VR應用在需求以及優化上是存在本質區別的。如果你想讓一個單獨的項目同時生成在PC端和安卓端上,那么必須注意遵循更加嚴格的移動開發最佳實踐
(best practices)。
Thisdocument describes the mobile Unity integration release 0.4.3. Most informationcontained in this guide also applies to the PC Unity integration .4.4. Any exceptionsare clearly indicated where they occur (e.g., the Moonlight folder in OVRcontains assets relevant only to mobile development).
本文檔描述了移動Unity整合包,版本0.4.3。本指南中包含的絕大多數信息也可以同時運用在PC Unity整合包里.4.4。如有不同之處一般都會當場指出(比如說OVR里的Moonlight文件夾里包含的組件只和移動開發有關)
Requirements需求
Systemand Hardware Requirements系統和硬件需求Pleasereview the relevant documentation to be sure that you are using supportedhardware and that your development environment and devices are configured andset up properly:
? PCSDK: OculusDeveloper Guide
?Mobile SDK: Deviceand Environment Setup Guide
Beforebeginning Unity development, you should be able to run the available SDK Unitydemo applications.
請參閱相關文檔以確保你使用的是受支持的硬件設備,同時確保你的開發環境及硬件都已經經過了正確的調試和安裝:
? PC端SDK: OculusDeveloper Guide
? 移動端SDK: Deviceand Environment Setup Guide
在開始Unity開發工作之前,你應該可以先運行一下手頭已經擁有了的SDK Unity Demo應用
。UnityRequirements Unity需求
TheOculus Unity Integration is compatible with Unity Pro 4.6.1 , which includessupport for Lollipop (Android 5.0).
整合包可以由Unity Pro 4.6.1進行編譯,因為其也包含了對Lollipop棒棒糖(安卓5.0)的支持。
Note:For mobilebuilds, we strongly recommend using Unity 4.6.2p2 or higher, which includeimportant fixes for a memory leak and a null reference bug.
注意:對于移動端的生成,我們強烈建議使用Unity 4.6.2.p2或者更高的版本,因為會對內存溢出或者空引用BUG的情況作出重要修正。
Unity Free support is available with Unity 4.6 or higher. Afeature set comparison between Unity Pro and Unity Free may be found here: http://unity3d.com/unity/licenses
對Unity4.6或更高版本提供了Unity免費版的支持。Pro版和免費版的功能有哪些區別可以參考文檔http://unity3d.com/unity/licenses
Note: Thereare noteworthy feature support differences between Unity licenses. Pleasereview the limitations cited below as well as the license comparison on Unity’swebsite before committing considerable resources to one path. Your licensechoice will depend largely on the performance characteristics and distributionneeds of your app.
注意:對于Unity許可證書之間對功能支持的區別,其中有某些地方值得一看。請在安排工作之前參閱下列Unity網址中的限制條件以及許可證書中的區別。對許可證類型的選擇在很大程度上依賴于你的應用的表現形式和分布需求。
Gamepad Controller
You may wish to have a compatible gamepad controller for use withthe supplied demo applications, such as the Xbox 360 controller for Windows, anHID-compliant game controller for Mac, or a Samsung EI-GP20 or other compatiblecontroller for Gear VR.
Oculus Unity
游戲控制器
你也許會需要有一個可供編譯的游戲手柄在受支持的Demo應用當中,比如對應windows的Xbox 360手柄,對應Mac的HID-compliant游戲手柄或者一部三星 EI-GP20或其他對應Gear
VR的其他可編譯控制器。
Oculus/GearVR開發者群 302294234
Installation安裝
All Oculus Unity development materials are available for downloadat our Developer site (requires login): https://developer.oculus.com/downloads/
所有的OculusUnity開發所需材料都可以在我們的開發者平臺上下載到(需要登錄)https://developer.oculus.com/downloads/The Oculus Unity Integration is the heart of the supplieddevelopment resources - it installs the minimum set of required files necessaryfor VR integration into Unity. We have also included various assets, scripts,and sample applications to assist with development.Oculus Unity
整合包是整個開發資源中的核心——它會在最低限度上為你安裝所有必要的用以開發VR的文件。我們同樣在里面放入了多種組件、腳本以及應用實例來輔助開發過程。The Mobile SDK also includes Unity example source code illustratingthe construction and use of common resources such as simple rooms, menus, andmore. They may be found in the folder SDKExamples. See Oculus Mobile SDKExamples formore information.移動SDK同樣包含了Unity實例資源代碼來說明各種結構以及大部分資源的使用方法比如simpleRooms、Menus等等。它們可以在文件夾SDKExamples里找到。參閱Oculus MobileSDKExamples 以獲得更多信息。The PC Unity Integration bundle includes PC Unity整合包捆綁內容有:? OculusUnityIntegration(Oculus Unity 整合包)The mobile SDK includes the following移動SDK包含有:? OculusUnityIntegration(Oculus Unity 整合包)? BlockSplosion sample application (source and pre-built apk) 應用實例 (資源以及預生成apk)? Shadowgun sample application (pre-built-apk) 應用實例 (預生成apk)? SDKExamples (source) (資源)Preparing for Development: PC SDK準備工作:PC SDKWhen developing for PC, we recommend beginning with the Oculus Developer Guide and theOculus Best Practices Guide, whichincludes information and guidelines for developing great VR experiences, andshould be considered a go-to reference when designing your Oculus-ready games.當在PC上做開發時,我們推薦先從OculusDeveloper Guide 和Oculus Best Practices Guide兩部文檔開始,因為它們包含了如何開發牛逼VR體驗項目的信息和指導,而且當你準備好要設計一個Oculus作品時也可以將它們作為一個直觀的參考。Direct Mode Display Driver直觀顯示模式驅動On Windows, Oculus recommends users install the Oculus DisplayDriver, which includes a feature known as Direct Display Mode. In direct mode,the driver makes your Rift behave as an appliance instead of a standard Windowsdisplay. Applications target the Rift by loading the driver and pointingrendering to it before initialization. This is the default behavior. Forcompatibility, the Rift can also still be used as a Windows monitor.在windows上,Oculus推薦用戶安裝上Oculus Display Driver,其中有個功能叫做Direct Display Mode(直觀顯示模式)。在直接模式里,驅動程序會將你的Rift設置為取代Windows標準屏幕的顯示器。應用程序在讀取驅動之后會直接標記Rift并在初始化之前先行把渲染工作做好。這是一種默認的行為模式。為了考慮兼容性,Rfit也能作為windows的顯示屏來使用。This is known as Extended Display Mode. When extended mode isactive, rendering works as usual, with no Oculus intervention. You can choosethe mode from the Oculus Configuration Utility's Rift Display Mode screen.這被稱為擴展顯示模式。當擴展模式是激活的,渲染就照常工作不用人為干預。你可以選擇應用程序的屏幕顯示模式。The direct mode driver is not yet available for platforms otherthan Windows.目前windows之外的平臺還不提供直觀模式的驅動程序。Monitor Setup顯示器設置To get the best experience, you and your users should alwaysconfigure the Rift correctly.為了能得到最好的體驗,最好總是將Rift調試到最佳狀態。In Windows 7 and Windows 8, you can change Windows' displaysettings by right-clicking on the desktop and selecting Screen resolution.在win7和win8里,你可以直接更改windows的顯示設置,右鍵點桌面選個性化即可。? It is possible to clone the same image on all of your displays.To ensure each display uses the correctfrequency, Oculus recommends extending the desktop instead ofcloning it.? 可以把圖像克隆到不同的屏幕上。但為了確保每個屏幕都使用了正確的頻率,Oculus推薦最好還是擴展桌面而不是簡單復制。? If you are using the Rift in extended mode, it should be set toits native resolution. This is 1920x1080 for DK2 and 1280x800 for DK1.? 如果你是在擴展模式下使用Rift,那么最好將它設置為原生分辨率。對于DK2來說是1920x1080,對DK1來說就是1280x800。On Mac systems open System Preferences, and then navigateto Displays.在Mac系統里打開系統設置,定位到顯示菜單。? As with Windows, it is possible to mirror the same image on allof your displays. Oculus recommends against mirroring. Click *Arrangement *andensure *Mirror Displays *is not enabled.? 在windows里可以直接把圖像鏡像到所有屏幕上。但Oculus推薦還是不要鏡像。點擊Arrangement并確保Mirror Displays沒有啟用。? Some Unity applications will only run on the main display. Inthe *Arrangement *screen, drag the white bar onto the Rift's blue box tomake it the main display.? 有些Unity應用只會在主要屏幕上顯示。在Arrangement界面,拖動白條把Rift的藍色盒子設置為主屏幕。? Always use the Rift's native resolution and frequency. Click GatherWindows. For DK2, the resolutionshould be Scaled to 1080p, the rotation should be 90° andthe refresh rate should be 75 Hertz. For DK1, the resolution should be1280x800, the rotation should be Standard, and the refresh rate should be 60Hertz.? 常態保持Rift為原生分辨率和頻率。點擊GatherWindows。對DK2來說,分辨率應該調Scaled到1080p,旋轉角(rotation)應該是90°而刷新率應該是75Hz。對DK1來說,分辨率應該是1280x800,旋轉角設置為標準,刷新率應該是60Hz。Recommended Configuration推薦配置We recommend the following settings in your project:我們推薦項目工程采用如下配置:? On Windows, enable Direct3D 11. D3D 11 and OpenGL expose themost advanced VR rendering capabilities. In some cases, using D3D 9 may resultin slightly reduced visual quality or performance.? 在windows上,啟用Direct3D 11。D3D 11和Open GL能最大限度展現VR的渲染能力。在某些情況下,用D3D 9可能會導致畫質或表現的輕微下降。? Use the Linear Color Space. Linear lighting is not only morecorrect for shading, it also causes Unity to perform sRGB read/write to the eyetextures. This helps reduce aliasing during VR distortion rendering, where theeye textures are interpolated with slightly greater dynamic range.? 使用線性的顏色空間(linear color space)。線性光并不僅僅正確作用于著色(shading),它還可以讓Unity在肉眼材質上展現sRGB的讀/寫。這一點可以幫助VR在渲染失真時降低混淆程度,尤其是在肉眼材質被輕微的大動態范圍(slightly greater dynamic range)改動時。? Never clone displays. When the Rift is cloned with anotherdisplay, the application may not vsync properly.This leads to visible tearing or judder (stuttering or vibratingmotion).? 不要復制屏幕。當Rift被克隆到另一塊屏幕時,應用程序可能沒辦法完美同步。很有可能導致視界撕裂或者抖動(斷斷續續或者運動震動)。? On Windows, always run DirectToRift.exe. Even in extended mode,DirectToRift.exe makes your application run full-screen on the Rift.? 在windows上保持運行DirectToRift.exe。哪怕在擴展模式中,DirectToRift.exe也能讓你的應用程序在Rift上保持全屏。? When using the Unity editor, use extended display mode. Directmode is currently supported only forstandalone players. Using it with the Unity editor will result ina black screen on the Rift.? 在使用Unity編輯器時,使用擴展屏幕模式。直觀模式目前僅支持單一玩家。用Unity編輯器打開它有可能會導致Rift上的黑屏。Oculus/GearVR開發者群 302294234Preparing for Development: Mobile SDK準備開發:移動SDKWhen developing for mobile, please be sure to fully review all ofthe relevant performance and designdocumentation, especially the MobileUnity Best Practices guide. Mobile apps are subject tomore stringent limitations and requirements and computational limitations whichshould be taken into consideration from the ground up.當針對移動端進行開發時,請先保證完全瀏覽過所有相關的表現和設計文檔,特別是Mobile Unity Best Practices guide.移動應用意味著要一直考慮更嚴格的限制和需求以及從頭到尾都要一直考慮的計算限制。We hope that the process of getting your Oculus device integratedinto your Unity environment is a fun and easy experience.我們希望把你的Oculus硬件整合進Unity環境里的過程能變得有趣和輕松。Getting Started開始This section describes steps taken to begin working in Unity.這個版塊描述了如何開始用Unity展開工作。Importing the Unity Integration導入Unity整合包If you are already working in a Unity project, save your workbefore beginning.如果你已經做好準備要進行Unity的項目開發了,記得在開始之前先存個檔。First, create a new project that you can import the Oculus assetsinto. From the Unity menu, select *File *> New Project. Clickthe *Browse *button and select the folder where the Unity project will belocated.Make sure that the *Setup defaults for: *field is set to 3D.首先,創建一個新的項目來導入Oculus組件。在Unity菜單里,選擇文件—新項目。點擊Browse按鈕選擇放置Unity項目的文件夾位置。確保Setup defaults for:區域選擇的是3D。You do not need to import any standard or pro Unity assetpackages, as the Oculus Unity integration is fully selfcontained.不需要再導入任何標注或Pro Unity組件包,因為Oculus Unity整合包已經完全包含進去了。Click the *Create *button. Unity will reopen with the newproject loaded.點擊Create按鈕,Unity會重啟并讀取新的項目。To import the Integration into Unity, select *Assets *> *CustomPackage... *and select the Unity Integration .unitypackage to import theassets into your new project. Alternately, you can locate the .unitypackagefile and double-click to launch, which will have the same effect.要想把整合包導入Unity,選擇Asset—Custom Package…并選擇Unity Intergration.unitypackage來把組件都導入到你的新項目里。當然你也可以直接雙擊那個文件,效果是一樣的。When the *Importing package *dialog box opens, leave all ofthe boxes checked and select Import. The import process may take a fewminutes to complete.當Importingpackage日志框彈出時,全選所有內容并點擊導入。整個過程可能會持續幾分鐘時間來完成。Mobile SDK: the mobile Unity Integration includes a ProjectSettings folder which provides default settings for a VR mobile application.You may manually copy these files to your [Project]/Assets/ProjectSettingsfolder.移動SDK:移動Unity整合包包含了一個Project Settings文件夾,可以為VR移動應用提供默認設置。你也可以自行將這些文件復制到你的[項目]/Assets/ProjectSettings文件夾下。Importing Sample Applications導入實例In this section we'll describe how to import sample Unityapplication source into Unity, using BlockSplosion as an example.在這個環節我們會描述一下如何把一個簡單的Unity應用資源導入到Unity中,就拿BlockSplosion作為例子吧。Note: Sampleapplication import is relevant to mobile only. The Room sample applicationprovided for PC development is included as a scene in the UnityIntegrationpackage.注意:實例應用的導入只與移動端有關。為PC開發而提供的Room實例已經作為一個場景被添加到Unity整合包里了。If you are already working in a Unity project, save your workbefore beginning.如果已經準備好在Unity項目上開始工作,先記得存個檔。To import the Integration into Unity, select *Assets *> *CustomPackage... *and select BlockSplosion.unitypackage to import the assets intoyour new project. Alternately, you can locate the BlockSplosion.unitypackagefile and double-click to launch, which will have the same effect.The import process may take a few minutes to complete.點Assets/CustomPackage… 選擇BlockSplosion.unitypackage來把所有組件導入新項目里。當然,直接雙擊文件也行。過程會持續幾分鐘時間。Adding VR to an Existing Unity Project將VR添加到已有的項目中The Unity Integration package may be used to integrate Oculus VRinto an existing project. This may be useful as a way of getting oriented to VRdevelopment, but dropping a VR camera into a Unity game that wasn't designedwith VR best practices in mind is unlikely to produce a great experience.Unity整合包可以用來將Oculus VR整合進一個已有的項目里。在面向VR開發的道路上這個方法會非常有用,但是把一個VR攝像頭隨便扔進一個并不是為VR設計的Unity游戲中,如果事先并沒有在腦海里經過仔細構想(bestpractices)的話,可能沒辦法產生良好的體驗效果。Note: This isone simple method for adding VR to an existing application, but is by no meansthe only way. For example, you may not always wish to use OVRPlayerController.注意:這只是一個將VR添加到已有應用程序的簡單方案,絕不是唯一方法。舉例說明,你大概也不想總是用OVRPlayerController。1. Importpackage2. InstantiateOVRCameraRig if you already have locomotion figured out or instantiateOVRPlayerController to walk around.3. Copyany scripts from the non-VR camera to the OVRCameraRig. Any image effectsshould go to both the Left/RightEyeAnchor GameObjects that are children of theOVRCameraRig.4. Disableyour old non-VR camera.5. Buildyour project and run normally.1. 導入包2. 實例化一個OVRCameraRig,如果你已經搞懂了移動方面的內容或者通過實例化OVRPlayerController來負責移動。3. 把所有非VR攝像頭的腳本都復制到OVRCameraRig里。所有的圖像效果都應該直接放到OVRCameraRig下的Left/RightEyeAnchorGameObjects里。4. 把你之前的非VR攝像頭通通Disable掉。5. 像平常那樣生成你的項目并運行。A Detailed Look at the Unity Integration從細節看Unity整合包This section examines the Unity integration, including thedirectory structure of the integration, the Unity prefabs are described, andseveral key C# scripts.這個環節開始著重分析Unity整合包,包括整合包的目錄結構,Unity預制體的描述以及幾個關鍵的C#腳本。Note: Thereare minor differences between the contents of the Unity Integration providedfor PC development and the version bundled with the mobile SDK.注意:分別針對PC開發和捆綁在移動SDK上的Unity 整合包在內容上幾乎沒什么區別。Contents內容OVRThe contents of the OVR folder inOculusUnityIntegration.unitypackage are uniquely named and should be safe toimport into an existing project.在OculusUnityIntegration.unitypackage中的OVR文件夾里的內容都是獨特命名的,而且應該可以安全導入已有的項目里。The OVR directory contains the following subdirectories:OVR路徑下包含著如下的分支路徑:<ignore_js_op>
OVRDisplay 提供HMD渲染時的狀態以及姿態(pose)。
OVRTracker 提供姿態(pose)、視錐體,以及紅外追蹤攝像頭的追蹤狀態。
OvrCapi
OvrCapi is a C# wrapper for LibOVR (specifically, CAPI). Itexposes all device functionality, allowing you to query and set capabilitiesfor tracking, rendering, and more. Please refer to the Oculus Developer Guideand reference manual for details.
OvrCapi是一個LibOVR(亦稱,CAPI)的C#封裝。它把所有的硬件功能都展示出來,使你可以查詢或設置那些追蹤、渲染等一些能力。欲知詳情請參考Oculus開發者指南和操作手冊。
OVRCommon OVRCommon is a collection of reusable static functions,including conversions between Unity and OvrCapi types.
OVRCommonOVRCommon是一系列可重用的靜態功能,包括了Unity和OvrCapi之間類型的轉換。
Utilities公用部分
The following classes are optional. We provide them to help youmake the most of virtual reality, depending on
the needs of your application.
下列類都是可選的。我們提供這些東西是為了幫助你完成VR中的大部分工作,主要看你的應用需要哪些了。
OVRPlayerController OVRPlayerController為VR框架實現第一人稱視角的控制。它綁定在OVRPlayerController預制體上,同時捆綁的還有一個OVRCameraRig。
在一個Unity場景下這個控制器會產生良好的互動效果,當然,需要場景為其分配一個碰撞檢測。
OVRPlayerController包含了數個用滑塊控制的變量,可以用來改變控制器的物理屬性。包括了加速(玩家增速有多快)、抑速(當玩家停止輸入移動指令時速度削減的快慢)、后方與側方抑速(從后方和側方加速的減慢速度)、旋轉量(在Y軸上旋轉玩家,按度數/幀計算)、以及重力調節計(當玩家在半空中時的下降加速度)。
當設置了HMD旋轉Y時,實際上的攝像頭的Y軸旋轉角會采用其父變換矩陣(parent transform)的Y軸旋轉值。
OVRPlayerController的預制體有一個空的GameObject叫做ForwardDirection。這個對象包含了一個矩陣,力的控制方向就是在它上面。這個對象同樣用來放置玩家能看到的主體幾何面
OVRGamepadController 這是一個接口類,連接游戲控制器。
在windows系統下,游戲控制器必須是兼容X軸輸入的。
注意:目前原生的兼容X軸輸入的控制器都不支持Mac OS。碰到這種情況請使用傳統的Unity輸入方案來解決這個問題。
OVRMainMenu 用來控制不同場景間的讀取工作。同時渲染出一個可以讓玩家在VR框架中進行設置的菜單,同時允許把設置結果存起來以便今后使用。
使用這個組件的用戶可以按照自己喜好添加各種場景進去。
為了方便起見,OVRMainMenu可以同時加進OVRCameraRig和OVRPlayerController預制體中。
OVRCrosshair 是一個渲染和控制屏幕上的十字準線的輔助類。目前由OVRMainMenu組件來控制。
OVRGUI 是一個輔助類,不管2D還是3D的基礎渲染文本,它都可以對其進行封裝。
不推薦用2D版本的代碼來渲染3D元素(在當前使用OVRMainMenu的時候)。
OVRGridCube 是一個輔助類,當它啟用時會顯示所有cube的網格。它的主要目的是用來為用戶的視野位置找一個理想的中心點。當位置追蹤啟用時尤其有用。當位置數據可用時cube會變為紅色,不可用時會保持藍色,或者在失去視野時由紅變藍。
OVRPresetManager 是一個輔助類,當使用Unity PlayerPrefs類時可以用來儲存一系列變量以供使用。
OVRVisionGuide 目前由OVRMainMenu組件來使用。
Oculus Mobile SDKExamples
Oculus移動SDK實例
The SDK Examples project (included with the mobile SDK only)demonstrates useful scenarios and functionality.
SDK實例項目(只包括在移動SDK中)里有比較有用的場景和功能。
To import SDKExamples into Unity, begin by creating a new, emptyproject. Then select *Assets *> *Custom Package... *and selectSDKExamples.unityPackage to import the assets into your project. Alternately,you can locate the SDKExamples.unityPackage and double-click to launch, whichwill have the same effect.
要將其引入Unity,首先創建一個空的項目(具體過程省略)然后把SDKExamples.unityPackage部件導入到項目里。當然雙擊package也行。
Once imported, replace your Unity project's ProjectSettings folderwith the ProjectSettings folder included with SDKExamples.
導入之后,把原來Unity項目里的ProjectSettings文件夾用SDKExamples里的ProjectSettings文件夾替換掉。