GvrPointerInputModule

This script provides an implemention of Unity's BaseInputModule class.

Summary

Exists so that Canvas-based (uGUI) UI elements and 3D scene objects can be interacted with in a Gvr Application.

This script is intended for use with either a 3D Pointer with the Daydream Controller (Recommended for Daydream), or a Gaze-based-Pointer (Recommended for Cardboard).

To use, attach to the scene's EventSystem object. Be sure to move it above the other modules, such as TouchInputModule and StandaloneInputModule, in order for the Pointer to take priority in the event system.

If you are using a Canvas, set the Render Mode to World Space, and add the GvrPointerGraphicRaycaster script to the object.

If you'd like pointers to work with 3D scene objects, add a GvrPointerPhysicsRaycaster to the main camera, and add a component that implements one of the Event interfaces (EventTrigger will work nicely) to an object with a collider.

GvrPointerInputModule emits the following events: Enter, Exit, Down, Up, Click, Select, Deselect, UpdateSelected, and GvrPointerHover. Scroll, move, and submit/cancel events are not emitted.

To use a 3D Pointer with the Daydream Controller:

  • Add the prefab GoogleVR/Prefabs/UI/GvrControllerPointer to your scene.
  • Set the parent of GvrControllerPointer to the same parent as the main camera (With a local position of 0,0,0).

To use a Gaze-based-pointer:

  • Add the prefab GoogleVR/Prefabs/UI/GvrReticlePointer to your scene.
  • Set the parent of GvrReticlePointer to the main camera.

Inheritance

Inherits from: BaseInputModule, IGvrInputModuleController

Public attributes

scrollInput = new GvrPointerScrollInput()
Manages scroll events for the input module.
vrModeOnly = false
bool
If true, pointer input is active in VR Mode only.

Properties

CurrentRaycastResult
static RaycastResult
Gets the current RaycastResult.
EventExecutor
Gets the executor this module uses to process events.
Impl
Gets the implementation object of this module.
Pointer
Gets or sets the static reference to the GvrBasePointer.
RaycastResultCache
List< RaycastResult >
Gets the list of raycast results used as a cache.
eventSystem
new EventSystem
Gets the event system reference.

Public static functions

FindEventExecutor()
Helper function to find the Event executor that is part of the input module if one exists in the scene.
FindInputModule()
Helper function to find the input module if one exists in the scene and it is the active module.
OnPointerCreated(GvrBasePointer createdPointer)
void
The GvrBasePointer calls this when it is created.

Public functions

Deactivate()
void
Deactivate this instance.
DeactivateModule()
override void
FindCommonRoot(GameObject g1, GameObject g2)
new GameObject
Finds the common root between two GameObjects.
FindFirstRaycast(List< RaycastResult > candidates)
new RaycastResult
Finds the first raycast.
GetBaseEventData()
new BaseEventData
Gets the base event data.
IsPointerOverGameObject(int pointerId)
override bool
Process()
override void
ShouldActivate()
bool
Whether the module should be activated.
ShouldActivateModule()
override bool

Public attributes

scrollInput

GvrPointerScrollInput scrollInput = new GvrPointerScrollInput()

Manages scroll events for the input module.

vrModeOnly

bool vrModeOnly = false

If true, pointer input is active in VR Mode only.

If false, pointer input is active all of the time.

Set to false if you plan to use direct screen taps or other input when not in VR Mode.

Properties

CurrentRaycastResult

static RaycastResult CurrentRaycastResult

Gets the current RaycastResult.

The current RaycastResult.

EventExecutor

GvrEventExecutor EventExecutor

Gets the executor this module uses to process events.

The executor this module uses to process events.

Impl

GvrPointerInputModuleImpl Impl

Gets the implementation object of this module.

The implementation object of this module.

Pointer

static GvrBasePointer Pointer

Gets or sets the static reference to the GvrBasePointer.

The static reference to the GvrBasePointer.

RaycastResultCache

List< RaycastResult > RaycastResultCache

Gets the list of raycast results used as a cache.

The list of raycast results used as a cache.

eventSystem

new EventSystem eventSystem

Gets the event system reference.

The event system reference.

Public static functions

FindEventExecutor

GvrEventExecutor FindEventExecutor()

Helper function to find the Event executor that is part of the input module if one exists in the scene.

Details
Returns
A found GvrEventExecutor or null.

FindInputModule

GvrPointerInputModule FindInputModule()

Helper function to find the input module if one exists in the scene and it is the active module.

Details
Returns
A found GvrPointerInputModule or null.

OnPointerCreated

void OnPointerCreated(
  GvrBasePointer createdPointer
)

The GvrBasePointer calls this when it is created.

If a pointer hasn't already been assigned, it will assign the newly created one by default. This simplifies the common case of having only one GvrBasePointer so it can be automatically hooked up to the manager. If multiple GvrBasePointers are in the scene, the app has to take responsibility for setting which one is active.

Details
Parameters
createdPointer
The pointer whose creation triggered this call.

Public functions

Deactivate

void Deactivate()

Deactivate this instance.

DeactivateModule

override void DeactivateModule()

FindCommonRoot

new GameObject FindCommonRoot(
  GameObject g1,
  GameObject g2
)

Finds the common root between two GameObjects.

Details
Parameters
g1
The first GameObject.
g2
The second GameObject.
Returns
The common root.

FindFirstRaycast

new RaycastResult FindFirstRaycast(
  List< RaycastResult > candidates
)

Finds the first raycast.

Details
Parameters
candidates
The list of RaycastResults to search for the first Raycast.
Returns
The first raycast.

GetBaseEventData

new BaseEventData GetBaseEventData()

Gets the base event data.

Details
Returns
The base event data.

IsPointerOverGameObject

override bool IsPointerOverGameObject(
  int pointerId
)

Process

override void Process()

ShouldActivate

bool ShouldActivate()

Whether the module should be activated.

Details
Returns
Returns true if this module should be activated, false otherwise.

ShouldActivateModule

override bool ShouldActivateModule()