Oculus Unity Development Guide开发

2016-08-26  本文已影响1130人  Moment__格调

转自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文件夹替换掉。

上一篇下一篇

猜你喜欢

热点阅读