Setting up the Unity environment
Like all projects, we will begin by launching Unity and creating a new project. The first steps will create a project folder which contains several files and directories:
- Launch the Unity application.
- Choose the New option after the application splash screen loads.
- Create a new project by launching the Unity application. Save the project as Trappist1 in a location of your choice, as demonstrated in Figure 2.2:
To prepare for VR, we will adjust the Build Settings and Player Settings windows.
- Open Build Settings from File | Build Settings.
- Select the Platform for your target device (iOS or Android).
- Click the Switch Platform button to confirm the change. The Unity icon in the right-hand column of the platform panel indicates the currently selected build platform. By default, it will appear next to the Standalone option. After switching, the icon should now be on Android or iOS platform, as shown in Figure 2.3:
Note for Android developers: Ericsson Texture Compression (ETC) is the standard texture compression format on Android. Unity defaults to ETC (default), which is supported on all current Android devices, but it does not support textures that have an alpha channel. ETC2 supports alpha channels and provides improved quality for RBG textures on Android devices that support OpenGL ES 3.0.
Since we will not need alpha channels, we will stick with ETC (default) for this project:
- Open the Player Settings by clicking the button at the bottom of the window. The PlayerSetting panel will open in the Inspector panel.
- Scroll down to Other Settings (Unity 5.5 thru 2017.1) or XR Settings and check the Virtual Reality Supported checkbox.
- A list of choices will appear for selecting VR SDKs. Add Cardboard support to the list, as shown in Figure 2.4:
- You will also need to create a valid Bundle Identifier or Package Name under Identification section of Other Settings. The value should follow the reverse-DNS format of the com.yourCompanyName.ProjectName format using alphanumeric characters, periods, and hyphens. The default value must be changed in order to build your application.
Bundle Identifiers are unique. When an app is built and released for Android, the Bundle Identifier becomes the app's package name and cannot be changed. This restriction and other requirements are discussed in this Android documentation link: http://developer.Android.com/reference/Android/content/pm/PackageInfo.html.
Apple development note:
Once you have registered a Bundle Identifier to a Personal Team in Xcode, the same Bundle Identifier cannot be registered to another Apple Developer Program team in the future. This means that, while testing your game using a free Apple ID and a Personal Team, you should choose a Bundle Identifier that is for testing only, you will not be able to use the same Bundle Identifier to release the game. An easy way to do this is to add Test to the end of whatever Bundle Identifier you were going to use, for example, com.MyCompany.VRTrappistTest. When you release an app, its Bundle Identifier must be unique to your app, and cannot be changed after your app has been submitted to the App Store.
- Set the Minimum API Level to Android Nougat (API level 24) and leave the Target API on Automatic.
- Close the Build Settings window and save the project before continuing.
- Choose Assets | Import Package | Custom Package... to import the GoogleVRForUnity.unitypackage previously downloaded from http://developers.google.com/cardboard/unity/download. The package will begin decompressing the scripts, assets, and plugins needed to build a Cardboard product.
- When completed, confirm that all options are selected and choose Import.
Once the package has been installed, a new menu titled GoogleVR will be available in the main menu. This provides easy access to the GoogleVR documentation and Editor Settings. Additionally, a directory titled GoogleVR will appear in the Project panel:
- Right-click in the Project and choose Create | Folder to add the following directories: Materials, Scenes, and Scripts.
- Choose File | Save Scenes to save the default scene. I'm using the very original Main Scene and saving it to the Scenes folder created in the previous step.
- Choose File | Save Project from the main menu to complete the setup portion of this project.