Building for Oculus Rift
To build for Oculus Rift you can use OpenVR. But if you plan to publish in the Oculus Store and/or use Oculus-specific SDK for other high-value features offered in the Oculus ecosystem, you will need to build to the Oculus SDK, as follows:
- Configure your Unity Build Settings to target the Standalone platform
- In Player Settings, under XR Settings, set Virtual Reality Enabled
- Ensure Oculus is at the top of the Virtual Reality SDKs list.
- Download and Install the Oculus Integration package from the Asset Store, as instructed previously
Now we will add the OVR camera rig to the MeMyselfEye object in our scene:
- Look in your Project window, under the Assets folder you should have a folder named OVR.
- Within that is a subfolder called Prefabs. Drag the prefab named OVRCameraRig from the Assets/OVR/Prefabs/ folder into your Hierarchy. Place it as a child object of MeMyselfEye.
- Set its Y position to 1.6 by setting its Transform to Position to (0, 1.6, 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 OVR camera rig should be set to your desired height (1.6 in this case), which will be accommodated at runtime based on the height you configured in the Oculus runtime device configuration.
To test it out, make sure that the VR device is properly connected and turned on. You should have the Oculus runtime 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 thumbstick, you can make Ethan walk, run, and jump just like we did earlier.
Note that the Oculus package installs helpful menu items on the Unity Editor menu bar. We won't go into details here, and they are subject to change. We encourage you to explore the options and shortcuts they provide. See the screenshot:
To include Oculus Dash support, you must use Oculus OVR version 1.19 or later (included with Unity 2017.3 or later). Then:
- In Player Settings, XR panel, unfold the Oculus SDK for additional settings
- Check the Shared Depth Buffer checkbox
- Check the Dash Support checkbox:
For more information on Oculus Dash support in Unity, see https://developer.oculus.com/documentation/unity/latest/concepts/unity-dash/.
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 Oculus, see https://developer.oculus.com/documentation/unity/latest/concepts/book-unity-gsg/.