@[TOC](Table of Contents)
Building a VR Development Environment with Unity#
Choose unity2018.3.6f1+steamVR1.2.3+VRTK3.3 for better compatibility.
Tested: Before starting formal development, it is best to install the virtual reality environment drivers and choose the corresponding plugin versions to avoid many pitfalls and errors.
HTC VIVE Environment Configuration#
Virtual reality applications require the configuration of virtual reality hardware drivers. The hardware device for this project is HTC VIVE, so you need to download the driver from this website and follow the prompts to install and configure the hardware: https://www.vive.com/cn/setup/vive/.
Steam VR Environment Configuration#
The Steam VR environment is a common environment for most VR software, and this project also requires support from Steam VR. You can browse related information about Steam VR and download Steam at this website: https://store.steampowered.com/steamvr/.
Click the green Install Steam button at the top right of the webpage to download the Steam installer and install it. After installing Steam, you need to manually install Steam VR.
Creating Function Import Plugin Check Environment#
Find a plugin with good compatibility; I am using steamVR1.2.3+VRTK3.3. I will upload these two plugins at the end of the article. Import them into Assets, and in the popped-up SteamVR window, click the Accept All button to set up the Steam VR environment, with no other error messages indicating it is usable:
Creating a VR Interaction Environment#
This project uses VRTK in conjunction with SteamVR to quickly configure the VR environment. Open the VRTK->Prefabs folder in the Plugins folder, find the SDKSetupSwitcher prefab, and drag it into the Hierarchy window:
In the Hierarchy, create an empty object named Create Empty, rename it to VRTK_SDKManager, and set its position and rotation parameters to zero. Drag the SDKSetupSwitcher under this empty object to make it a child object. Similarly, create an empty object named VRTK_Scripts and create LeftController and RightController empty objects as its child objects, also setting their position and rotation parameters to zero:
Next, you need to add the VRTK_Controller Events component to both empty objects to implement VRTK listening for controller events. Here, LeftController and RightController actually represent the left and right hands in the virtual environment. Therefore, related scripts and objects on the controllers (such as UI) can be placed on these two empty objects.
Next, we will add the pre-made VRTK components to the empty objects. Select VRTK_SDKManager, click the Add Component button in the Inspector panel on the right, search for VRTK_SDK Manager in the popped-up menu, and click to add this component:
VRTK supports multiple VR device SDKs. In this project, only the SteamVR SDK is installed, so you need to create an SDKSetup (SDK configuration) based on SteamVR. By referencing VRTK's standards, VRTK can uniformly obtain the corresponding input and output configurations.
Create an empty object under VRTK_SDKManager, name it SteamVR, and change its Y-axis position to 0.5. Add the VRTK_SDKSetup component to the empty object and select the SteamVR option in the Quick Select section of the component:
In the Project window, navigate to the Plugins/SteamVR/Prefabs directory, and drag the Camera and SteamVR prefabs under the newly created SteamVR empty object. At this point, check the properties panel of SteamVR, and the red warning should disappear:
Thus, the SDK configuration is complete. VRTK can provide a simulator for a VR environment, which can be viewed from the Plugins/VRTK/Prefabs directory. Create a new SDK configuration named Simulator, and drag the VRSimulatorCameraRig prefab from the directory under this empty object as its child object, setting the SDK Setup to Simulator.
Next, configure the SDKManager and enable it. Select VRTK_SDKManager, and in the VRTK_SDK Manager component's Setups option, click the Auto Populate button to enable the SDKManager configuration and automatically sort it. At the same time, drag the left and right hand objects from VRTK_Scripts to the corresponding positions in the Script Aliases section.
Finally, create a folder named Prefabs in the Project window, and drag the SDKManager and left and right hand objects into this folder to generate prefabs for future use.
Testing the VR Environment#
Test the created VR interaction environment. If the development environment is not connected to a VR device, it will automatically select the VRTK simulator for testing. We can perform operations such as moving, rotating, and changing the controller position in the simulator based on the UI prompts in the upper left corner. During runtime, you can click the Switch SDK Setup button in the upper right corner to change the VR environment. If there are no other error messages in the Console window, it runs successfully.
The error shown in the image can be ignored, mainly because the VR device is not connected. Once connected, it will naturally disappear. During runtime, the built-in simulator Simulator from VRTK is used for convenient interaction testing later.
Download steamVR1.2.3+VRTK3.3:
https://download.csdn.net/download/qq_42437783/16608509[Click this link to download the related plugins](https://download.csdn.net/download/qq_42437783/16608509)