VR For Developers

You are on page 1of 38

Vr for developers

1.
Which sdk to develop on unity ?
Unity (or Unreal Engine) is currently a big mess when it comes to
AR/VR. Each constructor has his own SDK, so you can’t “easily”
develop a game/app once and run it everywhere.
OpenXR is a royalty-free, open standard that provides
high-performance access to Augmented Reality (AR) and Virtual
Reality (VR) - collectively known as XR - platforms and devices.
Unity and Unreal Engine both are working bringing OpenXR
support to their respective engines… but it’s not released yet.
Unity has developed new XR plugins with the move to a plugin
architecture future support for OpenXR… and there is no
simulator (so need HMD to dev/test).
https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@0.9/manual/index.html
2.
What can we use now ?
https://github.com/ViveSoftware/ViveInputUtility-Unity/wiki

The VIVE Input Utility (VIU) from HTC is a toolkit for developing
VR experiences in Unity, especially with the VIVE/VIVE Pro but
also targeting many platforms from a common code base
including Oculus Rift, Rift S Go, Quest, Google Daydream, VIVE
Wave SDK (e.g. VIVE Focus standalone) and more… and there is
a simulator.
3.
Installing VIU
Instead of starting from scratch, we will use this demo project.
https://github.com/ludonkey/demotraining
https://github.com/ludonkey/demovr (final version)
Open the AssetStore window and search for “Vive Input Utility”,
choose “Download” and “Import”.
Open the Edit > Preferences > VIU Settings and active the
Simulator.
4.
Setup the player
REMOVE

Remove the previous Player and the Camera.


Drag &
drop

Drag&drop the ViveRig Prefab.


HMD
Add the AudioListener
component to this Object
+ AudioSource linked to
Right hand “Dream_Escape”
Left hand

We need to re-add the AudioListener to the Player.


And the AudioSource linked to the AudioClip “Dream_Escape”
You can now “Play” and look around with your mouse.
5.
Wasd/QE (US) => zqsd/AE (fr)

(You can skip this step if you are using a QWERTY keyboard.)
Replace the content of this file:
Assets\HTC.UnityPlugin\VRModule\Modules\SimulatorModule.cs
By this version.
6.
Setup the teleportation
Choose the Ground game object and add the Teleportable
component.
7.
Repair the collectibles
Update the collectible.cs script.
using HTC.UnityPlugin.ColliderEvent;
using UnityEngine;

public class Collectible : MonoBehaviour, IColliderEventHoverEnterHandler


{
private AudioSource bouncingSound;
private GameController gameController;

void Start()
{
bouncingSound = GetComponent<AudioSource>();
gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
}

void OnCollisionEnter(Collision other)


{
if (other.gameObject.tag == "Ground")
{
bouncingSound.Play();
}
}

public void OnColliderEventHoverEnter(ColliderHoverEventData eventData)


{
gameController.PlayerCollected(gameObject);
}
}
8.
Grab interaction
Create a Cube, set scale x,y,z to 0.25
Add the Rigidbody component
Add the BasicGrabbable component
If you want to change the material during the Grab process,
you can use the MaterialChanger component.
9.
UI world-space
Remove the EventSystem.
Set RenderMode of the Canvas to “Word Space”
Remove the Canvas Scaler
Remove The Graphic Raycaster
Add The Canvas Raycast Target
= 10 / 1920
After choosing a controller, toggle the laser pointer with the Menu (M).
If you add a button to the canvas you can now interact with it.
10.
Populate collectibles with this button
Set the Nb Cube To Instantiate to 1
public void PopulateCollectibles()
{
for (int i = 0; i < nbCubeToInstanciate; i++)
{
float x = Random.Range(-playAreaWidth / 2.0f, playAreaWidth / 2.0f);
float z = Random.Range(-playAreaWidth / 2.0f, playAreaWidth / 2.0f);
float y = Random.Range(spawnMinHeight, spawnMaxHeight);
Vector3 randomPos = new Vector3(x, y, z);
Instantiate(collectiblePrefab, randomPos, explosionPrefab.transform.rotation);
}
}

Inside the GameManager script,


Change the visibility of PopulateCollectibles to public.
Call the PopulateCollectibles method of the GameManager
when clicking on the button.
10.
Run/Build on a real vr headset
HTC vive (pro) / Valve Index
Oculus Rift (S) BUT DON’T USE THAT,
instead see the next page

Oculus Quest

Open the Edit > Preferences > VIU Settings and active the
targeted platform.
Steam just updated his SDK, install it from the Asset Store.
11.
Go further
Design, Develop, and Deploy for VR

https://learn.unity.com/course/oculus-vr

You might also like