Creating an Application Using the Template
Getting Started#
UNIGINE has a ready-to-use template for making VR projects in C#. It supports Oculus Rift and HTC Vive / Vive Pro (OpenVR) out of the box. It also provides a sample project (VR Sample). Here, you will find a set of 3D models of all popular VR controllers and the implementation of basic mechanics such as grabbing and throwing objects, pressing buttons, opening/closing drawers, and a lot more.
The world in this sample project has its settings optimized for best performance in VR.
Both the template and the sample project are created using the Component System — components attached to objects determine their functionality.
You can extend an object's functionality simply by assigning it more components. For example, the laser pointer object in the VR Sample has the following components attached:
- VRTransformMovableObject — enables grabbing and throwing an object
- VRLaserPointer — enables casting a ray of light by the object
You can also implement custom components to extend functionality.
The main features of the VR Sample:
- VR support (OpenVR-compatible devices including Oculus Rift, HTC Vive, and others)
- A set of physical objects that can be manipulated via controllers (physical objects, buttons, drawers)
- An interactive laser pointer object
- Teleportation around the scene
- GUI
- Interaction with GUI objects via controllers
Let's create a project based on the C# VR Template.
- Open SDK Browser, go to the My Projects tab, and click Create New.
-
In the Create New Project window, specify the project name VRProject, select VR in the Template menu, then C#(.NET) in the API+IDE menu, and select Float in the Precision menu. Then click Create New Project.
- When the project is successfully created, open it in UnigineEditor.
- In the Asset Browser, open the vr_sample.world file located in the data/vr_template/vr_sample/ folder. We will work with this world.
Structure Overview#
Now, let's learn a bit more about the template structure. All components that implement the basic VR functionality are assigned to the corresponding nodes organized in the hierarchy with the vr_layer root node (see the picture below):
A player is represented by the hierarchy of nodes with the vr_player node in the root (a Player Dummy camera), to which the VRPlayer component is assigned. The component implements the player's logic. The child nodes of vr_player represent models of HMDs and controllers, to which all necessary components are assigned to configure interactions and main parameters.
VRInput is the main component that implements operations on user input, it includes all available devices, controllers, controls (controllers + common ones), event handlers, and so on. Input parameters for each type of device, functionality for polling the status of controls, etc. are implemented in the corresponding classes (PCInput, ViveInput, OculusInput). The functionality of the devices is implemented in the components inherited from the VRHeadController component (for HMDs — ViveHeadController, OculusHeadController, PCHeadController) and from the VRHandController component (for controllers — ViveHandController, OculusHandController, PCHandController).
The VRMovementManager component is used for movement management. Different types of movements (rotating, walking, teleporting) are implemented in the components inherited from the base VRBaseMovement component (TurnMovement, WalkMovement, TeleportationMovement + implementation of movements for the VR emulation mode with keyboard control).
The VRInteractionManager component is used for interaction management. Different types of interactions are implemented in the components inherited from the base VRBaseInteraction component:
- RHandMenuInteraction — interaction with the menu using controllers
- VRHandShapeInteraction — interaction with objects using controllers and the keyboard
- VRPCHeadMenuInteraction — interaction with the menu for the VR-emulation mode with keyboard control
- VRBaseInteractable is a base component for all interactive objects (objects you can interact with). It defines the main interactions: here you specify the available actions with the object. You can also add your own interaction type.
The following components are inherited from VRBaseInteractable:
VRTransformMovableObject | This component type can be used for all objects that can be grabbed, held, and thrown (it can be a ball, a pistol, whatever you can take, carry and drop). |
VRKinematicMovableObject | This component type can be used for all objects that can be grabbed, held, and thrown (it can be a ball, a pistol, whatever you can take, carry and drop). |
VRPhysicMovableObject | This component type can be used for all objects that can be grabbed, held, and thrown (it can be a ball, a pistol, whatever you can take, carry and drop). |
VRObjectHandle | This component type can be used for all objects that can be rotated or moved while being held (various handles, levers, valves, etc.). |
VRObjectSwitch | This component type can be used for all objects that can be switched by grabbing (all sorts of buttons and on-off switches, including rotary ones). It can be used in combination with the VRNodeSwitchEnableByGrab component for additional effects. |
VRNodeSwitchEnableByGrab | This component type is used to control enabling/disabling of one or more nodes when grabbed. |
VRLaserPointer | This component enables casting a laser ray by the object. The laser pointer node has two components assigned — VRTransformMovableObject and VRLaserPointer. |
Setting Up a Device#
Suppose you have successfully installed your Head-Mounted Display (HMD) of choice (please visit Oculus Rift Setup or HTC Vive Setup if you did not). If you are having difficulties getting your HTC Vive to work, this Troubleshooting guide might be helpful.
Major VR devices (OpenVR-compatible) are supported out of the box.
Run the application and learn about basic mechanics, grab and throw objects, try to teleport and interact with objects in the scene.