Building for SteamVR
To target your app to use HTC VIVE you will use the OpenVR SDK. This SDK also supports Oculus Rift with Touch controllers, and Windows Immersive Mixed Reality (IMR) devices:
- Configure your Unity Build Settings to target the Standalone platform.
- In Player Settings, under XR Settings, set Virtual Reality to Enabled
- Ensure OpenVR is at the top of the Virtual Reality SDKs list.
- Download and Install the SteamVR Plugin from the Asset Store, as instructed previously.
- When you install SteamVR you may be prompted to accept recommended changes to your project settings. Unless you know better, we recommend you accept them.
Now we will add the SteamVR camera rig to the MeMyselfEye object in our scene:
- Look in your Project window; under the Assets folder, you should have a folder named SteamVR.
- Within that is a subfolder called Prefabs. Drag the prefab named [CameraRig] from the Assets/SteamVR/Prefabs/ folder into your hierarchy. Place it as a child object of MeMyselfEye.
- If necessary, reset its Transform to Position (0, 0, 0).
- Disable the Main Camera object, also under MeMyselfEye; you can disable objects by unchecking the enable checkbox in the top-left of its Inspector window. Alternatively, you can just delete the Main Camera object.
- Save the prefab by selecting MeMyselfEye in Hierarchy, then press its Apply button in the Inspector.
Note that the SteamVR camera rig Y position should be set to 0 as it will use the real-life height of the player to set the camera height in real time.
To test it out, make sure that the VR device is properly connected and turned on. You should have the SteamVR app opened on the Windows desktop. Click on the game Play button at the top-center of the Unity Editor. Put on the headset, and it should be awesome! Within VR, you can look all around—left, right, up, down, and behind you. You can lean over and lean in. Using the hand controller's thumb pad, you can make Ethan walk, run, and jump just like we did earlier.
Now you can build your game as a separate executable app using the following steps. Most likely, you've done this before, at least for non-VR apps. It's pretty much the same:
- 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 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 executable will be created in your Build folder. Run Diorama as you would do for any executable application: double-click on it.
For more information on Unity support for OpenVR, see https://docs.unity3d.com/Manual/VRDevices-OpenVR.html.