Oculus Unity Development Guide開發指南

轉自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>

Editor編輯器 包含可以為Unity編輯器添加功能的腳本,還有強化過的C#組件腳本。Materials材料 包含了整合包中圖形組件會用到的材料,比如主要GUI屏幕。Moonlight 包含了針對移動Gear VR開發而準備的類(僅針對移動端)。Prefabs預制體 包含了為了將VR嵌入Unity場景而提供框架的主要預制體:OVRCameraController和OVRPlayerController。Resources資源 包含了部分需要被OVR腳本實例化的預制體和其他對象,比如主GUI。Scene 場景包含了簡單的場景。Scripts腳本 包含了將VR框架和Unity組件結合起來的C#文件。許多腳本都要結合多種預制體一起使用。Shaders著色器 包含了多種Cg著色器,某些OVR組件會用得上。Textures紋理 包含了圖像部件,某些腳本組件會用得上。Note: Westrongly recommend that developers not directly modify the included OVR scripts.注意:我們強烈建議開發者們不要直接修改內置的OVR腳本。Plugins插件The Plugins folder contains the OculusPlugin.dll, which enablesthe VR framework to communicate with Unity on Windows (both 32 and 64-bitversions).插件文件夾包含了OculusPlugin.dll,能夠使VR框架得以和windows版Unity(32位和64位)交流數據。This folder also contains the plugins for other platforms:OculusPlugin.bundle for MacOS; and Android/ libOculusPlugin.so, vrlib.jar, andAndroidManifest.xml for Android.這個文件夾同樣包含了針對其他平臺的插件:OculusPlugin.bundle對應MacOS;Android/libOculusPlugin.so。vrlib.jar,還有對應安卓的AndroidManifest.xmlPrefabs預制體The current integration for adding VR support into Unityapplications is based on two prefabs that may be added into a scene:當前的整合包里向Unity應用添加VR支持的功能都來源于于兩個應該添加進場景的預制體。? OVRCameraRig? OVRPlayerControllerTo use, simply drag and drop one of the prefabs into your scene.要使用它們,拖過來扔到你場景里的預制體里就行。Note: You canalso add these prefabs into the scene from the Oculus - Prefabs menu.注意:你也可以通過Oculus-Prefabs菜單把這些預制體加入場景。OVRCameraRigOVRCameraRig replaces the regular Unity Camera within a scene. Youcan drag an OVRCameraRig into your scene and you will be able to start viewingthe scene with the Gear VR and Rift.OVRCameraRig在場景中用來替換掉常規的Unity Camera。你只要把這東西拖進場景就可以直接開始在Gear VR或者Rift里看到畫面了。Note: Makesure to turn off any other Camera in the scene to ensure that OVRCameraRig isthe onlyone being used.注意:確保關掉場景中的其他攝像頭,確保OVRCameraRig是唯一一個啟用的。Figure 15: Prefabs: OVRCameraRig,expanded in the inspector<ignore_js_op>
OVRCameraRig contains two Unity cameras, one for each eye. It ismeant to be attached to a moving object (such as a character walking around, acar, a gun turret, etc.) This replaces the conventional Camera.OVRCameraRig包含了兩個Unity攝像頭,倆眼一眼一個。本來目的是用來針對移動目標(比如一個到處走的角色,一輛車,一個炮塔等等),它替換掉的是傳統的攝像頭The following scripts (components) are attached to theOVRCameraRig prefab:下列腳本(組件)都附加在OVRCameraRig預制體上:? OVRCameraRig.cs? OVRManager.csOVRPlayerControllerThe OVRPlayerController is the easiest way to start navigating avirtual environment. It is basically an OVRCameraRig prefab attached to asimple character controller. It includes a physics capsule, a movement system,a simple menu system with stereo rendering of text fields, and a cross-haircomponent.可以說是最簡單的一種用來定位虛擬環境的方式了。它簡單來說就是把一個OVRCameraRig預制體跟一個簡單的character controller給綁在了一起。它包含了一個物理capsule,一個移動系統,一個簡單的有立體感文字區域渲染的菜單系統,還有一個cross-hair組件。To use, drag the player controller into an environment and beginmoving around using a gamepad, or a keyboard and mouse Note: Make sure thatcollision detection is active in the environment.要使用的話,把player controller拖到環境里面并且用游戲控制器來移動他,或者鍵盤和鼠標。注意:確認一下環境里面的碰撞檢測是不是激活狀態。Two scripts (components) are attached to the OVRPlayerControllerprefab:下列兩個腳本(組件)被綁定在OVRPlayerController預制體上:? OVRPlayerController.cs? OVRGamepadController.csFigure 16: Prefabs: OVRPlayerController,expanded in the inspector<ignore_js_op>
Unity ComponentsUnity組件The following section gives a general overview of what each of thescripts within the Scripts folder does.下面這個環節會告訴我們在腳本文件夾里的每個腳本大致上是做什么的。OVRCameraRigOVRCameraRig is a component that controls stereo rendering andhead tracking. It maintains three child "anchor" Transforms at theposes of the left and right eyes, as well as a virtual "center" eyethat is half-way between them.OVRCameraRig是一個控制立體感渲染和頭部運動追蹤的組件。它有三個子“錨點”分別提供左右眼位置的坐標,以及一個虛擬出來的在兩眼“中間”的眼睛。This component is the main interface between Unity and thecameras. This is attached to a prefab that makes it easy to add VR support to ascene.Important: All camera control should be done through thiscomponent. You should understand this script when implementing your own cameracontrol mechanism.這個組件是Unity和這個攝像頭之間主要的接口。這些都綁定在一個預制體上以便能更容易地把VR支持添加到場景里。OVRManagerOVRManager is the main interface to the VR hardware. It includeswrapper functions for all exported C++ functions, as well as helper functionsthat use the stored Oculus variables to help configure camera behavior.OVRManager是面向VR硬件的主要接口。它負責封裝所有導出的C++功能,以及一個輔助功能,可以用儲存的Oculus變量幫助調節攝像頭的行動。This component is added to the OVRCameraRig prefab. It can be partof any application object. However, it should only be declared once, becausethere are public members that allow for changing certain values in the Unityinspector.這個組件添加在OVRCameraRig預制體里。它可以成為任何應用程序對象的一部分。不過它只能被declare一次,因為在Unity的inspector里存在允許改變某些值的public成員。OVRManager.cs contains the following public members:OVRmanage.cs包含如下public成員:Table 4: Mobile and PC Public Members移動和PC端的public成員<ignore_js_op>
Monoscopic單屏 如果設置為true,那么渲染工作就會試圖把原本對應倆眼的渲染方式優化成單視角。不能對應所有平臺。EyeTexture Format肉眼紋理格式 設置肉眼渲染紋理的格式。一般情況下你應該使用Default或者DefaultHDR來對應高動態范圍渲染。EyeTexture Depth肉眼紋理深度 設置肉眼渲染紋理的深度精度。有可能會用付出性能代價的方式來修復z-fighting效果。EyeTexture Antialiasing肉眼紋理抗鋸齒 為肉眼渲染紋理設置抗鋸齒等級。Table 5: PC-Only Public Members只在PC端獨有的public成員<ignore_js_op>
NativeTexture Scale原生紋理比例 在camera controller里的每一個攝像頭都會創建一個渲染紋理,有著能獲得最清晰的像素密度的理想比例(一個1-to-1的像素尺寸能在屏幕中間展示透鏡失真效果)。這個區域可以用來把一個攝像頭的渲染對象從尺寸的角度調整到可以針對多個理想像素保真度的程度,以便讓你能夠在性能和質量之間找到平衡點。VirtualTexture Scale虛擬紋理比例 如有必要,這個區域可以用來動態調整攝像頭的渲染對象,以使其值低于理想狀態下的像素密度,可以在運行時幫助降低GPU占用。UsePosition Tracking 使用位置追蹤 如果禁用,則由追蹤器偵測到的位置坐標會停止更新HMD坐標。UseRotation Tracking 使用旋轉角追蹤 如果禁用,則由追蹤器偵測到的定向會停止更新HMD定向。Mirrorto Display 鏡像屏幕 如果Oculus直觀顯示驅動已被啟用,而且這個選項也被選中的話,畫面會在除了Rift之外的桌面窗口中出現。禁用這個選項會輕微提高性能。TimeWarp(desktop only)時間扭曲(僅供桌面)TimeWarp是一個調整經過渲染的圖像在屏幕上顯示位置的技術,當某個時間點用戶能看到它的時候給予最后追蹤姿態的情況作出調整。啟用這個選項會強制執行垂直同步,并且會使其他時間上的調整的等待時間降低。FreezeTime Warp(desktop only) 凍結時間扭曲(僅供桌面)啟用這個選項會在時間扭曲時暫時凍結經過渲染的眼部姿態(renderedeye pose)來說明這個效果。ResetTracker On Load 讀取時重置追蹤器 這個選項默認為True。關掉的話,在讀取隨后的場景時將不會重置追蹤器。這樣就可以在場景切換時保持原有的朝向了,同時會保持磁力計(magnetometer)設置完整。Helper Classes輔助類In addition to the above components, your scripts can alwaysaccess the HMD state via static members of OVRManager. 除了上述組件之外,你的腳本還會經常通過OVRManager里的靜態成員訪問HMD狀態。<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開發者指南和操作手冊。

<ignore_js_op>

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中的大部分工作,主要看你的應用需要哪些了。

<ignore_js_op>
<ignore_js_op>

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文件夾替換掉。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 227,488評論 6 531
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,034評論 3 414
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 175,327評論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,554評論 1 307
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,337評論 6 404
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 54,883評論 1 321
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 42,975評論 3 439
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,114評論 0 286
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,625評論 1 332
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,555評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,737評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,244評論 5 355
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 43,973評論 3 345
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,362評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,615評論 1 280
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,343評論 3 390
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,699評論 2 370

推薦閱讀更多精彩內容