Google Daydream
To build for Google Daydream on mobile Android devices, you will use the Daydream SDK. You must set up your development machine for Android development as described above. Then complete the following steps:
- Configure your Unity Build Settings to target the Android platform
- In Player Settings, under XR Settings, set Virtual Reality Enabled
- Ensure Daydream is at the top of the Virtual Reality SDKs list
- Download and Install the Google VR SDK package, as instructed previously
We will now build the MeMyselfEye camera rig for our scene. At the present time, the best example we have is the GVRDemo example scene provided with the Google VR SDK (can be found in the Assets/GoogleVR/Demos/Scenes/ folder):
- In your scene Hierarchy, create an empty game object under the MeMyselfEye (select the MeMyselfEye object, right-click, select Create Empty). Name it MyGvrRig.
- Set its height to 1.6 by setting its Transform to Position to (0, 1.6, 0).
- From the Project folders, locate the provided prefabs (Assets/GoogleVR/Prefabs).
- Drag a copy of each of the following prefabs from the Project folder to Hierarchy as a child of MyGvrRig:
- Headset/GvrHeadset
- Controllers/GvrControllerMain
- EventSystem/GvrEventSystem
- GvrEditorEmulator
- GvrInstantPreviewMain
- Leave the Main Camera object under MeMyselfEye and enable it. The GoogleVR uses the existing Main Camera object.
- Save the prefab by selecting MeMyselfEye in Hierarchy, then press its Apply button in the Inspector.
The GvrHeadset is a VR camera properties manager. The GvrControllerMain provides support for the Daydream 3DOF hand controller. We will use GvrEventSystem in later chapters; it provides a drop-in replacement for Unity's Event System object. The GvrEditorEmulator is not actually part of your app but enables previewing your scene in the Unity Editor when you press Play. Likewise, adding GvrInstantPreviewMain lets you preview your app on your phone when you press Play in the editor.
These are the prefabs that we know we’re going to want to use. Certainly, go ahead and explore the other prefabs provided in the SDK. See https://developers.google.com/vr/unity/reference/.
We also recommend you take a look at Google Daydream Elements which provides additional demos and scripts "for developing high-quality VR experiences." We introduce this in the next chapter. See https://developers.google.com/vr/elements/overview.
When you’re ready, you can build your game as a separate executable app using the following steps:
- From the main menu bar, navigate to File | Build Settings....
- If the current scene is not already in the Scenes to Build list, press Add Open Scenes.
- Click on Build and Run and set its name to Diorama.
- I like to keep my builds in a subdirectory named Build; create one if you want to.
- Click on Save.
An Android APK file will be created in your Build folder and uploaded to your attached Android phone.