GvrBasePointer

This is an abstract class.

This abstract class should be implemented for pointer based input, and used with the GvrPointerInputModule script.

Summary

It provides methods called on pointer interaction with in-game objects and UI, trigger events, and 'BaseInputModule' class state changes.

To have the methods called, an instance of this (implemented) class must be registered with the GvrPointerManager script in 'Start' by calling GvrPointerInputModule.OnPointerCreated.

This abstract class should be implemented by pointers doing 1 of 2 things:

  1. Responding to movement of the users head (Cardboard gaze-based-pointer).
  2. Responding to the movement of the daydream controller (Daydream 3D pointer).

Inheritance

Inherits from: MonoBehaviour, IGvrControllerInputDeviceReceiver
Direct Known Subclasses:GvrLaserPointer, GvrReticlePointer

Public types

RaycastMode{
  Camera,
  Direct,
  Hybrid
}
enum

Public attributes

overridePointerCamera
Determines the eventCamera for GvrPointerPhysicsRaycaster and GvrPointerGraphicRaycaster .
raycastMode = RaycastMode.Hybrid
Determines which raycast mode to use for this raycaster.

Properties

CameraRayIntersectionDistance
float
When using the Camera raycast mode, this is used to calculate where the ray from the pointer will intersect with the ray from the camera.
ControllerInputDevice
CurrentPointerRadius
float
If ShouldUseExitRadiusForRaycast is true, returns the exitRadius.
CurrentRaycastResult
RaycastResult
Convenience function to access what the pointer is currently hitting.
IsAvailable
bool
If true, the pointer will be used for generating input events by GvrPointerInputModule .
IsPointerIntersecting
bool
IsTouching
bool
If true, the user is currently touching the touchpad.
MaxPointerDistance
abstract float
Returns the max distance from the pointer that raycast hits will be detected.
MaxPointerEndPoint
Vector3
Returns the end point of the pointer when it is MaxPointerDistance away from the origin.
PointerCamera
PointerIntersection
Vector3
PointerTransform
Transform
Returns the transform that represents this pointer.
ShouldUseExitRadiusForRaycast
bool
This is used to determine if the enterRadius or the exitRadius should be used for the raycast.
TouchDown
bool
If true, the user just started touching the touchpad.
TouchPos
Vector2
Position of the current touch, if touching the touchpad.
TouchUp
bool
If true, the user just stopped touching the touchpad.
TriggerDown
bool
If true, the trigger was just pressed.
TriggerUp
bool
If true, the trigger was just released.
Triggering
bool
If true, the trigger is currently being pressed.

Public functions

GetPointAlongPointer(float distance)
Vector3
Returns a point in worldspace a specified distance along the pointer.
GetPointerRadius(out float enterRadius, out float exitRadius)
virtual abstract void
Return the radius of the pointer.
GetRayForDistance(float distance)
Returns the ray used for projecting points out of the pointer for the given distance.
OnPointerClickDown()
virtual abstract void
Called when a click is initiated.
OnPointerClickUp()
virtual abstract void
Called when click is finished.
OnPointerEnter(RaycastResult raycastResult, bool isInteractive)
virtual abstract void
Called when the pointer is facing a valid GameObject.
OnPointerExit(GameObject previousObject)
virtual abstract void
Called when the pointer no longer faces an object previously intersected with a ray projected from the camera.
OnPointerHover(RaycastResult raycastResultResult, bool isInteractive)
virtual abstract void
Called every frame the user is still pointing at a valid GameObject.

Public static functions

CalculateHybridRay(GvrBasePointer pointer, RaycastMode hybridMode)
Calculates the ray for the segment of the Hybrid raycast determined by the raycast mode passed in.
CalculateRay(GvrBasePointer pointer, RaycastMode mode)
Calculates the ray for a given Raycast mode.

Protected functions

Start()
virtual void

Structs

GvrBasePointer.PointerRay

Represents a ray segment for a series of intersecting rays.

Public types

RaycastMode

 RaycastMode
Properties
Camera

Casts a ray from the camera through the target of the pointer.

This is ideal for reticles that are always rendered on top. The object that is selected will always be the object that appears underneath the reticle from the perspective of the camera. This also prevents the reticle from appearing to "jump" when it starts/stops hitting an object.

Recommended for reticles that are always rendered on top such as the GvrReticlePointer prefab which is used for cardboard apps.

Note: This will prevent the user from pointing around an object to hit something that is out of sight. This isn't a problem in a typical use case.

When used with the standard daydream controller, the hit detection will not account for the laser correctly for objects that are closer to the camera than the end of the laser. In that case, it is recommended to do one of the following things:

  1. Hide the laser.
  2. Use a full-length laser pointer in Direct mode.
  3. Use the Hybrid raycast mode.

Direct

Cast a ray directly from the pointer origin.

Recommended for full-length laser pointers.

Hybrid

Default method for casting ray.

Combines the Camera and Direct raycast modes. Uses a Direct ray up until the CameraRayIntersectionDistance, and then switches to use a Camera ray starting from the point where the two rays intersect.

Recommended for use with the standard settings of the GvrControllerPointer prefab. This is the most versatile raycast mode. Like Camera mode, this prevents the reticle appearing jumpy. Additionally, it still allows the user to target objects that are close to them by using the laser as a visual reference.

Public attributes

overridePointerCamera

Camera overridePointerCamera

Determines the eventCamera for GvrPointerPhysicsRaycaster and GvrPointerGraphicRaycaster .

Additionaly, this is used to control what camera to use when calculating the Camera ray for the Hybrid and Camera raycast modes.

raycastMode

RaycastMode raycastMode = RaycastMode.Hybrid

Determines which raycast mode to use for this raycaster.

• Camera - Ray is cast from the camera through the pointer. • Direct - Ray is cast forward from the pointer. • Hybrid - Begins with a Direct ray and transitions to a Camera ray.

Properties

CameraRayIntersectionDistance

float CameraRayIntersectionDistance

When using the Camera raycast mode, this is used to calculate where the ray from the pointer will intersect with the ray from the camera.

ControllerInputDevice

GvrControllerInputDevice ControllerInputDevice

CurrentPointerRadius

float CurrentPointerRadius

If ShouldUseExitRadiusForRaycast is true, returns the exitRadius.

Otherwise, returns the enterRadius.

CurrentRaycastResult

RaycastResult CurrentRaycastResult

Convenience function to access what the pointer is currently hitting.

IsAvailable

bool IsAvailable

If true, the pointer will be used for generating input events by GvrPointerInputModule .

IsPointerIntersecting

bool IsPointerIntersecting

IsTouching

bool IsTouching

If true, the user is currently touching the touchpad.

Used by GvrPointerScrollInput to generate OnScroll events using Unity's Event System. Defaults to ControllerInputDevice.GetButton(TouchPadTouch), can be overridden to change the input source.

MaxPointerDistance

abstract float MaxPointerDistance

Returns the max distance from the pointer that raycast hits will be detected.

MaxPointerEndPoint

Vector3 MaxPointerEndPoint

Returns the end point of the pointer when it is MaxPointerDistance away from the origin.

PointerCamera

Camera PointerCamera

PointerIntersection

Vector3 PointerIntersection

PointerTransform

Transform PointerTransform

Returns the transform that represents this pointer.

It is used by GvrBasePointerRaycaster as the origin of the ray.

ShouldUseExitRadiusForRaycast

bool ShouldUseExitRadiusForRaycast

This is used to determine if the enterRadius or the exitRadius should be used for the raycast.

It is set by GvrPointerInputModule and doesn't need to be controlled manually.

TouchDown

bool TouchDown

If true, the user just started touching the touchpad.

This is an event flag (it is true for only one frame after the event happens, then reverts to false). Used by GvrPointerScrollInput to generate OnScroll events using Unity's Event System. Defaults to ControllerInputDevice.GetButtonDown(TouchPadTouch), can be overridden to change the input source.

TouchPos

Vector2 TouchPos

Position of the current touch, if touching the touchpad.

If not touching, this is the position of the last touch (when the finger left the touchpad). The X and Y range is from 0 to 1. (0, 0) is the top left of the touchpad and (1, 1) is the bottom right of the touchpad. Used by GvrPointerScrollInput to generate OnScroll events using Unity's Event System. Defaults to ControllerInputDevice.TouchPos but translated to top-left-relative coordinates for backwards compatibility. Can be overridden to change the input source.

TouchUp

bool TouchUp

If true, the user just stopped touching the touchpad.

This is an event flag (it is true for only one frame after the event happens, then reverts to false). Used by GvrPointerScrollInput to generate OnScroll events using Unity's Event System. Defaults to ControllerInputDevice.GetButtonUp(TouchPadTouch), can be overridden to change the input source.

TriggerDown

bool TriggerDown

If true, the trigger was just pressed.

This is an event flag: it will be true for only one frame after the event happens. Defaults to mouse button 0 down on Cardboard or ControllerInputDevice.GetButtonDown(TouchPadButton) on Daydream. Can be overridden to change the trigger.

TriggerUp

bool TriggerUp

If true, the trigger was just released.

This is an event flag: it will be true for only one frame after the event happens. Defaults to mouse button 0 up on Cardboard or ControllerInputDevice.GetButtonUp(TouchPadButton) on Daydream. Can be overridden to change the trigger.

Triggering

bool Triggering

If true, the trigger is currently being pressed.

This is not an event: it represents the trigger's state (it remains true while the trigger is being pressed). Defaults to mouse button 0 state on Cardboard or ControllerInputDevice.GetButton(TouchPadButton) on Daydream. Can be overridden to change the trigger.

Public functions

GetPointAlongPointer

Vector3 GetPointAlongPointer(
  float distance
)

Returns a point in worldspace a specified distance along the pointer.

What this point will be is different depending on the raycastMode.

Because raycast modes differ, use this function instead of manually calculating a point projected from the pointer.

GetPointerRadius

virtual abstract void GetPointerRadius(
  out float enterRadius,
  out float exitRadius
)

Return the radius of the pointer.

It is used by GvrPointerPhysicsRaycaster when searching for valid pointer targets. If a radius is 0, then a ray is used to find a valid pointer target. Otherwise it will use a SphereCast. The enterRadius is used for finding new targets while the exitRadius is used to see if you are still nearby the object currently pointed at to avoid a flickering effect when just at the border of the intersection.

NOTE: This is only works with GvrPointerPhysicsRaycaster. To use it with uGUI, add 3D colliders to your canvas elements.

GetRayForDistance

PointerRay GetRayForDistance(
  float distance
)

Returns the ray used for projecting points out of the pointer for the given distance.

In Hybrid raycast mode, the ray will be different depending upon the distance. In Camera or Direct raycast mode, the ray will always be the same.

OnPointerClickDown

virtual abstract void OnPointerClickDown()

Called when a click is initiated.

OnPointerClickUp

virtual abstract void OnPointerClickUp()

Called when click is finished.

OnPointerEnter

virtual abstract void OnPointerEnter(
  RaycastResult raycastResult,
  bool isInteractive
)

Called when the pointer is facing a valid GameObject.

This can be a 3D or UI element.

raycastResult is the hit detection result for the object being pointed at. isInteractive is true if the object being pointed at is interactive.

OnPointerExit

virtual abstract void OnPointerExit(
  GameObject previousObject
)

Called when the pointer no longer faces an object previously intersected with a ray projected from the camera.

This is also called just before OnInputModuleDisabled previousObject will be null in this case.

previousObject is the object that was being pointed at the previous frame.

OnPointerHover

virtual abstract void OnPointerHover(
  RaycastResult raycastResultResult,
  bool isInteractive
)

Called every frame the user is still pointing at a valid GameObject.

This can be a 3D or UI element.

raycastResult is the hit detection result for the object being pointed at. isInteractive is true if the object being pointed at is interactive.

Public static functions

CalculateHybridRay

PointerRay CalculateHybridRay(
  GvrBasePointer pointer,
  RaycastMode hybridMode
)

Calculates the ray for the segment of the Hybrid raycast determined by the raycast mode passed in.

Throws an exception if Hybrid is passed in.

CalculateRay

PointerRay CalculateRay(
  GvrBasePointer pointer,
  RaycastMode mode
)

Calculates the ray for a given Raycast mode.

Will throw an exception if the raycast mode Hybrid is passed in. If you need to calculate the ray for the direct or camera segment of the Hybrid raycast, use CalculateHybridRay instead.

Protected functions

Start

virtual void Start()