Version: 2017.1
HoloLens
Single-Pass Stereo rendering

Google VR

Google VR encompasses both Daydream and Cardboard, two VR platforms owned by Google. See Google’s VR documentation for more information about the requirements and functionality of each.

Google VR applications are developed using Daydream. Daydream for Unity is a technical preview designed to give Unity developers early access to Google VR development. See Google’s Daydream documentation for more information about this.

This page provides a step-by-step guide to configuring Unity for Daydream development, and provides information on what you need to be aware of while developing for Daydream.

Empezando

Daydream’s minimum system requirement is Android API SDK version 21 (also known as “Lollipop”). If you don’t already have Lollipop, download it from the Google Android developer site.

You also need a Daydream-enabled phone. See Google’s documentation on Daydream hardware to learn how to set your Android phone up for Daydream development.

Configuring Unity for Daydream development

  1. In the main menu, go to Edit > Project Settings > Player.

  2. Click the Android logo to apply settings for building to Android (Box 1 in figure below).

  3. Open Other Settings, and under the Rendering section, tick the Virtual Reality Supported checkbox.

A list called Virtual Reality SDKs appears. Select the plus (+) icon at the bottom of the list.

From the drop-down, select Daydream. This then appears in the Virtual Reality SDKs list. Select the drop-down arrow next to it to expand the Daydream settings.

Property Function
Depth Format Use este desplegable para establecer la profundidad del buffer Z. Esto se usa para ordenar los datos visibles y determinar qué se representa realmente en la pantalla.
Foreground Icon Set the foreground icon for presentation in the VR Google Play store.
Background Icon Set the background icon for presentation in the VR Google Play store.
Use Sustained Performance Mode Enable Sustained Performance Mode for longer VR experiences. This reduces performance to improve battery life.

The minimum platform requirement for Daydream is Android 7.0 Lollipop (API level 21). To ensure Unity uses the correct APK, and only runs on devices upgraded to the latest version of Android, you need to change the Minimum API Level.

To do this in the Player Settings, navigate to Other Settings and under Identification use the Minimum API Level drop-down to set it to the latest API in the list.

Target API Level should be set to API level 21 or higher for Cardboard and Daydream. By default, this property uses the highest level you have installed. For more information about API levels for Android, see documentation on Android PlayerSettings.

You are now ready create your Unity content for Daydream. Follow the same workflow you would for normal Android development (see documentation on Android development for more information), and ensure when you build and run your game (menu: File > Build & Run), you build and run it on a Daydream-capable phone.

Working with Daydream for Unity

When working with Daydream for Unity, note the following:

  • Use the device names daydream and cardboard to load a specific device when you want to enable VR for that device. To do this, call VRSettings.LoadDeviceByName and pass in the string name of the device.

  • Rendering is done side-by-side, over a single, double-wide Texture.

  • Integration of Daydream for Unity takes over the Unity activity’s view hierarchy. This means that any modification you make to the view hierarchy before you initialize Daydream for Unity is removed while in VR mode.

Daydream and Google Cardboard

Daydream and Cardboard have separate entries in the Virtual Reality SDKs list. Unity reads the list from top to bottom until it finds a device configuration that works, so the addition, removal or ordering of these devices in that list have consequences on built application functionality.

  • If Cardboard is above Daydream in the Virtual Reality SDKs list, the application might not run in Daydream mode, even on Daydream hardware.

  • If Daydream is the only item in the Virtual Reality SDKs list, VR Android Manifest entries are added so that the app appears in the VR-specific Google Play store. Asynchronous reprojection is a requirement for Daydream, so all devices which support Daydream also support asynchronous reprojection.

  • If Cardboard is the only item in the Virtual Reality SDKs list, the app does not appear in the VR Google Play store. Asynchronous reprojection and sustained performance mode are not enabled, even on capable hardware.

  • If both Daydream and Cardboard are in the Virtual Reality SDKs list, Asynchronous reprojection is enabled if running on supported hardware. Sustained performance mode is enabled if selected and if running on supported hardware. The app appears in all Google Play Stores.

Other VR SDKs

  • If you plan to support GearVR as well as Daydream and Cardboard, place Oculus at the top of the list. Phones that support GearVR run through the GearVR SDK, and phones that don’t support it fall back to Daydream or Cardboard.

  • If you add None as the first device in the list, Unity starts as a normal application and can be toggled into VR through script. See API documentation on VRSettings.enabled and VRSettings.LoadDeviceByName for more information.

Magic Window mode

Sometimes, you might want to apply a non-stereoscopic view with head tracking applied (for example, if you want to view a 2D image in VR, or provide a 2D preview of your VR application). This can be useful for promotional materials. To facilitate this, you can access head tracking data when VRSettings.enabled equals false and the VRSettings.loadedDeviceName is daydream or cardboard.

Por ejemplo:


UnityEngine.VR.VRSettings.enabled = false;
Camera.main.GetComponent<Transform>().localRotation = UnityEngine.VR.InputTracking.GetLocalRotation(VRNode.CenterEye);

See API documentation on VRSettings.LoadDeviceByName for more information.

Hardware volume controls

Daydream for Unity blocks the native OS from handling the hardware volume controls. This stops the OS from bringing up the volume UI when in VR mode. To handle the hardware volume controls yourself, extend the standard UnityPlayerActivity and handle onKeyDown and onKeyLongPress yourself.

For more information about this please see documentation on plug-ins for Android.

Unity does not block the volume controls from the Daydream controller.

Overriding Android libraries provided by Daydream

Daydream for Unity integration ships with two libraries to support Daydream development:

  • Daydream native library: gvr.aar

  • Google Protobuf Nano Java library: libprotobuf-java-nano.jar

You can override either of these libraries with newer or different versions of the libraries with the same name located in the Assets/Plugins/Android project folder. Names must match exactly in order for them to be correctly overridden.

API support

The following APIs are not supported by Daydream for Unity:

  • VRSettings.showDeviceView

  • VRDevice.isPresent

  • VRDevice.refreshRate

  • VRStats.gpuTimeLastFrame

Cardboard for iOS

Google distributes the Cardboard Native Development Kit (NDK) for iOS through the Cocoapods library management system. Unity is integrated with a specific version of that Cardboard NDK from the Cocoapods manager and uses the NDK to create your XCode project. This means the resulting project is generated differently from a standard Unity project; Cocoapods creates a wrapping XCode workspace that contains the Unity project as well as a project for the Cardboard NDK library and its dependencies. Always make sure that you open and/or use the workspace and not just the project to avoid getting linker errors due to the missing libraries from Cocoapods.


• 2017–06–07 Page amended with limited editorial review

HoloLens
Single-Pass Stereo rendering