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