Building for Google Cardboard
This section describes how to set up and build your VR project for Google Cardboard on a mobile phone, including Android smartphones and Apple iPhones (iOS). With this, you set up XR Plugin for Google Cardboard and configure your project so that it builds and runs on the mobile VR device.
Smartphone-based virtual reality is not as popular as it was when the previous editions of this book were written. Google no longer supports Daydream and has now open sourced the Cardboard SDK (https://github.com/googlevr/cardboard) as a baseline starter VR platform. Similarly, Oculus has dropped support for GearVR in its ecosystem. Nonetheless, Cardboard lives on, in both Android and iOS, as a fun and educational low-end VR display. The scene is displayed on the phone screen with separate left and right eye views that provide 3D stereographic viewing using a low-cost cardboard or plastic goggles with Fresnel lenses. Tracking is limited to three degrees of freedom (3DOF), which tracks your head's orientation in space but not its position.
Most of the projects in this book can run on smartphones with Cardboard, but maybe with some limitations. The only input device supported by Google Cardboard is a single button click. Unlike its next-level cousins (Daydream and GearVR), a Google Cardboard solution does not directly support Bluetooth hand controllers. However, a 3DOF handheld pointer controller can be bought for around $10 and used in your projects for pointing with a little extra work.
The following topics will review what it takes to set up your project for Google Cardboard with the Unity XR Platform on Android and iOS.
Setting up for Google Cardboard
The Google Cardboard XR plugin is an open source project supported by Google (not directly by Unity). At the time of writing, you must install the plugin usingPackage Manager using a GitHub URL. Please review the current Quickstart instructions on the Google page at https://developers.google.com/cardboard/develop/unity/quickstart before completing this section, as it may be more up to date than this book.
Use the following steps to install theGoogle Cardboard XR plugin:
- Open the Package Manager window usingWindow | Package Manager.
- Press the + button in the upper left of the window.
- SelectAdd Package from GIT URL.
- Paste the following URL: https://github.com/ValveSoftware/steamvr_unity_plugin.git#UnityXRPlugin.
- Open XR Management Settings usingEdit | Project Settings | XR Plug-in Management.
- Check the Cardboard XR Plugin checkbox in the Plug-in Providers list, as shown in the following screenshot:
Once the plugin has been installed, I recommend that you also install and review the "Hello Cardboard" sample package. In Package Manager | Google Cardboard Plugin for Unity, select the Samples | Hello Cardboard | Import button. In the installed assets is a sample scene called HelloCardboard you should open and try to Build And Run to verify your installation is complete and working, after finishing the following settings according to your platform.
The following Player Settings pertain to both Android and iOS projects. Open the Edit | Project Settings | Player window and do the following:
- In Player Settings | Resolution and Presentation, use the following setting:
- Default Orientation: Landscape Left
- In Player Settings | Splash Image, use the following setting:
- Show Splash Screen: Uncheck (Unity Plus and Pro only)
- In Player Settings | Other Settings, do the following:
- Specify the company domain under Package Name. Note that this defaults to the Company Name and Product Name fields at the top of the window.
Now, use these settings according to your target platform – Android or iOS.
Targeting Android for Cardboard
To target Android, configure your UnityBuild Settingsto target theAndroid platform, if it's not already (File | Build Settings... | Android | Switch Platform). Ensure your Unity install includes Android Build Support, along with the Android SDK and NDK tools and OpenJDK. See the Installing the Android tools section earlier in this chapter for more details.
Then, follow the instructions at https://developers.google.com/cardboard/develop/unity/quickstart for the specifics. I am not duplicating these instructions here because they are likely subject to change. Note that, currently, these instructions require you to create a Custom Main Gradle Template and edit the mainTemplate.gradle file in your project.
In the installed assets is a sample scene called HelloCardboard that you should open and try to Build And Run to verify your installation is complete and working.
Targeting iOS for Cardboard
This section will help you set up your Mac for iOS development from Unity for iPhones. The requirements are not specific to virtual reality; these are the same steps required for anyone building any iOS app from Unity. The process is also well-explained elsewhere, including the Unity documentation at https://docs.unity3d.com/Manual/iphone-GettingStarted.html. To participate in Apple's closed ecosystem, you must use a Mac as your development machine to develop for iOS. You will need to do/have the following:
- Have an Apple ID.
- Install Xcode.
- Set up a Provisioning Profile and Signing ID in Xcode.
- Configure the Unity Build Setting Target Platform.
- Configure the Unity Player Settings.
To target iOS, configure your UnityBuild Settingsso that they target theiOS platform, if it's not already (File | Build Settings... | iOS| Switch Platform). Ensure you have installed the iOS build modules using Unity Hub. Ensure your Unity install includes iOS Build Support. And, of course, you need to be developing on a Mac (OS X) and have Xcode installed (see https://docs.unity3d.com/Manual/iphone-GettingStarted.html).
Then, follow the instructions given at https://developers.google.com/cardboard/develop/unity/quickstart for the specifics. I am not duplicating the instructions here because they are likely subject to change.
In the installed assets is a sample scene called HelloCardboard that you should open and try to Build And Run to verify your installation is complete and working. Note that the iOS Cardboard companion app also needs to be installed on your phone so that you can run your Cardboard-based Unity project.