Old version (2.1.8 and before): WaveVR EventSystem
Unity provides Event System to receive input from standard I/O and communicate among different Game Objects.
In WaveVR, we provide several scripts and samples showing how to use Event System in a VR environment.
Developer can read the documents below to learn about the WaveVR Event System:
If a VR environment does not have a controller, how does the user control items?
The answer is Gaze.
Gaze is sending events through the Event System to the center of the screen where a user is looking.
When Game Objects receive events, corresponding actions are taken.
WaveVR provides a very easy way to use EventSystem for Gaze & Controller concurrently and steps are introduced below:
- Add Input Module:
Drag prefab Assets/WaveVR/Prefabs/InputModuleManager to scene. About this prefab, refer to Input Module Manager
- Add Controller:
Drag prefab Assets/WaveVR/Prefabs/ControllerLoader to scene. About this prefab, refer to WaveVR_ControllerLoader
- Customize Event Handler:
Event Handler is used to handle events . WaveVR provides a sample script WaveVR_EventHandler in Assets/WaveVR/Extra/EventSystem. Developer can simply copy the script and overwrite APIs in region #region override event handling function.
#region override event handling function public void OnPointerEnter (PointerEventData eventData) public void OnPointerExit (PointerEventData eventData) public void OnPointerDown (PointerEventData eventData) public void OnBeginDrag(PointerEventData eventData) public void OnDrag(PointerEventData eventData) public void OnEndDrag(PointerEventData eventData) public void OnDrop(PointerEventData eventData) public void OnPointerHover (PointerEventData eventData)
- Setup event UGUI:
Add WaveVR_AddEventSystemGUI to Canvas which can receive events.
Let’s have a practice from beginning.
Before start up, we need to prepare a scene, so creating a new scene as below:
Consider a scene always has 3D physical object(s), add a simple cube:
Consider a scene also has GUI(s), add a simple button:
When adding a Button, Canvas and EventSystem will also be added automatically.
Note: must change the Render Mode of Canvas to World Space:
Initial scene is ready now, let’s use EventSystem step-by-step:
- Remove Main Camera, drag WaveVR from Assets/WaveVR/Prefab/ - for enabling WaveVR rendering.
- Drag ControllerLoader prefab from Assets/WaveVR/Prefabs/ and choose options - for using a controller.
- Drag InputModuleManager prefab from Assets/WaveVR/Prefabs/.
- Add component WaveVR_AddEventSystemGUI to GUI (Canvas of Button).
- Add component WaveVR_EventHandler to Cube
Done. Now developer can play scene in editor mode to see the effect.
Hint: use Right-Alt + mouse to controll the controller in scene.