WaveVR_ControllerInputModule

Important: We do NOT encourage using this script directly. Please use Input Module Manager

Older versions (3.0.2 and before) can be found here: WaveVR_ControllerInputModule

Introduction

Please refer to WaveVR API Level for API compatibility.

Unity has Event System which lets objects receive events from an input and take corresponding actions.

An Input Module is where the main logic of how you want the Event System to behave lives, they are used for:

  • Handling input
  • Managing event mechanism
  • Sending events to scene objects.

This script supports an input module of multiple controllers.

Resources

  • Script:

    Assets/WaveVR/Scripts/WaveVR_ControllerInputModule.cs Assets/WaveVR/Extra/EventSystem/

  • Sample:

    Assets/Samples/ControllerInputModule_Test/

  • Prefab:

    Assets/WaveVR/Prefabs/ControllerLoader Assets/WaveVR/Prefabs/InputModuleManager

Samples

There are two sample scenes MouseInputModule_Test and VRInputModule_Test in Assets/Samples/ControllerInputModule_Test/

The sample VRInputModule_Test is introduced here.

1. InputModuleManager

_images/VRInputModule_Test.png

The prefab InputModuleManager is used to load WaveVR_ControllerInputModule

2. EventSystem

In runtime, WaveVR_ControllerInputModule is loaded by InputModuleManager and added into EventSystem like below photo:

_images/cim_eventsystem.png
  • Dominant / NonDominant Controller: Set up the event controller used by WaveVR_ControllerInputModule
  • Dominant / NonDominant Event Enabled: This option is used to enable the event of Dominant / NonDominant controller.
  • Dominant / NonDominant Raycast Mask: Set up the layer mask of EventSystem
  • Button To Trigger: Select the buttons used to trigger events. Note: the buttons should also be added in Buttons
  • Head: Keep this field be empty to use default WaveVR head. You can can refer to Input Module Manager to set up the other head.
  • Canvas Tag: This parameter is only useful in SDK3.0.2 and before.
  • Fixed Beam Length: If the controller beam mode is Fixed, this field indicates the length of the controller beam.

The controller of WaveVR_ControllerInputModule is loaded by WaveVR_ControllerLoader

If you want to use a customized controller, you have to

  • Create a controller pointer by using WaveVR_ControllerPointer
  • Create a controller beam by using WaveVR_Beam
  • Create a controller model, the layout of the controller looks like below photo:
_images/Generic_MC_R.png
  • Add the component WaveVR_SetAsEventSystemController to mention this controller is an Event Controller, e.g.
_images/cim_setaseventcontroller.png

Script

Work Flow

A raycaster is needed to send events. Unity uses the GraphicRaycaster for GUI and the PhysicsRaycaster for physical objects.

When an object is casted by the raycaster, the object will receive the Enter event and the previously casted object will receive the Exit event.

If the raycaster is hovering on an object, the object will receive the Hover events continuously.

// 1. Get graphic raycast object.
ResetPointerEventData (_dt);
GraphicRaycast (_eventController, _event_camera);

if (GetRaycastedObject (_dt) == null)
{
    // 2. Get physic raycast object.
    PhysicsRaycaster _raycaster = _controller.GetComponent<PhysicsRaycaster> ();
    if (_raycaster == null)
        continue;

    ResetPointerEventData (_dt);
    PhysicRaycast (_eventController, _raycaster);
}

// 3. Exit previous object, enter new object.
OnTriggerEnterAndExit (_dt, _eventController.event_data);

// 4. Hover object.
GameObject _curRaycastedObject = GetRaycastedObject (_dt);
if (_curRaycastedObject != null && _curRaycastedObject == _eventController.prevRaycastedObject)
{
    OnTriggerHover (_dt, _eventController.event_data);
}

Pointer Event Flow

As for the events of Event Trigger Type , the flow is shown below:

_images/eventflow.png

Summary:

  1. When the frame of a button changes briefly from unpressed to pressed:
  1. The Pointer Down event is sent.
  2. The initializePotentialDrag event is sent to the object that has a IDragHandler .
  1. When the frames of a button are pressed:
  1. The beginDrag event is sent.
  2. The Pointer Up event is sent to another object (different with current object) that received the Pointer Down event previously.
  3. The Drag event is sent continuously.
  1. When the frame of a button changes briefly from pressed to unpressed:
  1. The Pointer Up event is sent.
  2. The Pointer Click event is sent.
  3. If the Drag event has been sent before, the Pointer Drop event and the endDrag event will be sent.

As for the Enter, Exit and Hover events:

  • When raycasting an object, the Enter event will be sent.
  • When hovering over a raycasting object, the Hover event will be sent.
  • When leaving a raycating object, the Exit event will be sent.

Custom Defined Events

The WaveVR EventSystem locates in Assets/WaveVR/Scripts/EventSystem

The WaveVR_ExecuteEvents is used for sending the events.

The IWaveVR_EventSystem is used for receiving the events.

You do not need to implement the part of sending events, as it is managed in this script.

But if you want the GameObjects with custom scripts to receive events, the scripts should inherit the corresponding event interface:

public class WaveVR_EventHandler: MonoBehaviour,
    IPointerEnterHandler,
    IPointerExitHandler,
    IPointerDownHandler,
    IBeginDragHandler,
    IDragHandler,
    IEndDragHandler,
    IDropHandler,
    IPointerHoverHandler

The IPointerHoverHandler is a WaveVR defined event which is not part of Event Trigger Type .

Unity Mouse Mode

The WaveVR_ControllerInputModule provides two modes: the VR Mode (default) and the Unity Mouse Mode.

Another sample scene MouseInputModule_Test demonstrates the Unity Mouse Mode and uses Scripts/testeventhandler.cs to set the UnityMouseMode value in runtime.