Unity Virtual Reality Projects
上QQ阅读APP看书,第一时间看更新

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:

  1. Configure your Unity Build Settings to target the Standalone platform.
  2. In Player Settings, under XR Settings, set Virtual Reality to Enabled
  3. Ensure OpenVR is at the top of the Virtual Reality SDKs list.
  4. Download and Install the SteamVR Plugin from the Asset Store, as instructed previously.
  1. 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:

  1. Look in your Project window; under the Assets folder, you should have a folder named SteamVR.
  2. 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.
  3. If necessary, reset its Transform to Position (0, 0, 0).
  4. 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.
  5. 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:

  1. From the main menu bar, navigate to File | Build Settings...
  2. If the current scene is not already in the Scenes to Build list, press Add Open Scenes.
  3. Click on Build and set its name to Diorama.
  4. I like to keep my builds in a subdirectory named Build; create one if you want to.
  5. 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.