GvrControllerInput

Main entry point for the Daydream controller API.

Summary

To use this API, add this script to a game object in your scene, or use the GvrControllerMain prefab.

This is a singleton object. There can only be one object with this script in your scene.

To access a controller's state, get a device from GvrControllerInput.GetDevice then query it for state. For example, to the dominant controller's current orientation, use GvrControllerInput.GetDevice(GvrControllerHand.Dominant).Orientation.

Inheritance

Inherits from: MonoBehaviour

Public types

EmulatorConnectionMode enum

Events

OnControllerInputUpdated
static Action
Event handler for receiving button, touchpad, and IMU updates from the controllers.
OnPostControllerInputUpdated
static Action
Event handler for receiving a second notification callback, after all OnControllerInputUpdated events have fired.

Properties

Accel
static Vector3
Returns the dominant controller's current acceleration in meters per second squared.
ApiStatus
static GvrControllerApiStatus
Returns the status of the controller API.
AppButton
static bool
Returns true while the user holds down the dominant controller's app button.
AppButtonDown
static bool
Returns true in the frame the user starts pressing down the dominant controller's app button.
AppButtonUp
static bool
Returns true the frame after the user stops pressing down the dominant controller's app button.
BatteryLevel
static GvrControllerBatteryLevel
Returns the dominant controller's current battery charge level.
ClickButton
static bool
Returns true while the user holds down the dominant controller's touchpad button.
ClickButtonDown
static bool
Returns true in the frame the user starts pressing down the dominant controller's touchpad button.
ClickButtonUp
static bool
Returns true the frame after the user stops pressing down the dominant controller's touchpad button.
ErrorDetails
static string
If the dominant controller's state == GvrConnectionState.Error, this contains details about the error.
Gyro
static Vector3
Returns the dominant controller's current angular speed in radians per second, using the right-hand rule (positive means a right-hand rotation about the given axis), as measured by the controller's gyroscope.
HomeButtonDown
static bool
Returns true in the frame the user starts pressing down the dominant controller's system button.
HomeButtonState
static bool
Returns true while the user holds down the dominant controller's system button.
IsCharging
static bool
Returns true if the dominant controller is currently being charged.
IsTouching
static bool
Returns true while the user is touching the dominant controller's touchpad.
OnDevicesChanged
static Action
Event handler for when controller devices have changed.
OnStateChanged
Event handler for when the connection state of the dominant controller changes.
Orientation
static Quaternion
Returns the dominant controller's current orientation in space, as a quaternion.
Recentered
static bool
Returns true if the user just completed the recenter gesture.
Recentering
static bool
State
static GvrConnectionState
Returns the dominant controller's current connection state.
StatePtr
static IntPtr
Returns the GVR C library controller state pointer (gvr_controller_state*) for the dominant controller.
SupportsBatteryStatus
static bool
Returns true if battery status is supported.
TouchDown
static bool
Returns true in the frame the user starts touching the dominant controller's touchpad.
TouchPos
static Vector2
Position of the dominant controller's current touch, if touching the touchpad.
TouchPosCentered
static Vector2
Position of the dominant controller's current touch, if touching the touchpad.
TouchUp
static bool
Returns true the frame after the user stops touching the dominant controller's touchpad.

Public attributes

emulatorConnectionMode = EmulatorConnectionMode.USB
EmulatorConnectionMode
Indicates how we connect to the controller emulator.

Public functions

OnStateChangedEvent(GvrConnectionState state, GvrConnectionState oldState)
delegate void
Event handler for when the connection state of a controller changes.

Public static functions

GetDevice(GvrControllerHand hand)
Returns a controller device for the specified hand.

Public types

EmulatorConnectionMode

 EmulatorConnectionMode

Events

OnControllerInputUpdated

static Action OnControllerInputUpdated

Event handler for receiving button, touchpad, and IMU updates from the controllers.

Use this handler to update app state based on controller input.

OnPostControllerInputUpdated

static Action OnPostControllerInputUpdated

Event handler for receiving a second notification callback, after all OnControllerInputUpdated events have fired.

Properties

Accel

static Vector3 Accel

Returns the dominant controller's current acceleration in meters per second squared.

Returns Vector3.zero if GvrControllerInput is uninitialized. The controller's axes are:

  • X points to the right,
  • Y points perpendicularly up from the controller's top surface
  • Z lies along the controller's body, pointing towards the front Note that gravity is indistinguishable from acceleration, so when the controller is resting on a surface, expect to measure an acceleration of 9.8 m/s^2 on the Y axis. The accelerometer reading will be zero on all three axes only if the controller is in free fall, or if the user is in a zero gravity environment like a space station.

ApiStatus

static GvrControllerApiStatus ApiStatus

Returns the status of the controller API.

Returns GvrControllerApiStatus.Error if GvrControllerInput is uninitialized.

AppButton

static bool AppButton

Returns true while the user holds down the dominant controller's app button.

Returns false if GvrControllerInput is uninitialized.

AppButtonDown

static bool AppButtonDown

Returns true in the frame the user starts pressing down the dominant controller's app button.

Returns false if GvrControllerInput is uninitialized. Every AppButtonDown event is guaranteed to be followed by exactly one AppButtonUp event in a later frame. Also, AppButtonDown and AppButtonUp will never both be true in the same frame.

AppButtonUp

static bool AppButtonUp

Returns true the frame after the user stops pressing down the dominant controller's app button.

Returns false if GvrControllerInput is uninitialized. Every AppButtonUp event is guaranteed to be preceded by exactly one AppButtonDown event in an earlier frame. Also, AppButtonDown and AppButtonUp will never both be true in the same frame.

BatteryLevel

static GvrControllerBatteryLevel BatteryLevel

Returns the dominant controller's current battery charge level.

Returns GvrControllerBatteryLevel.Error if GvrControllerInput is uninitialized.

ClickButton

static bool ClickButton

Returns true while the user holds down the dominant controller's touchpad button.

Returns false if GvrControllerInput is uninitialized.

ClickButtonDown

static bool ClickButtonDown

Returns true in the frame the user starts pressing down the dominant controller's touchpad button.

Returns false if GvrControllerInput is uninitialized. Every ClickButtonDown event is guaranteed to be followed by exactly one ClickButtonUp event in a later frame. Also, ClickButtonDown and ClickButtonUp will never both be true in the same frame.

ClickButtonUp

static bool ClickButtonUp

Returns true the frame after the user stops pressing down the dominant controller's touchpad button.

Returns false if GvrControllerInput is uninitialized. Every ClickButtonUp event is guaranteed to be preceded by exactly one ClickButtonDown event in an earlier frame. Also, ClickButtonDown and ClickButtonUp will never both be true in the same frame.

ErrorDetails

static string ErrorDetails

If the dominant controller's state == GvrConnectionState.Error, this contains details about the error.

If GvrControllerInput is uninitialized this returns an error string describing the uninitialized state.

Gyro

static Vector3 Gyro

Returns the dominant controller's current angular speed in radians per second, using the right-hand rule (positive means a right-hand rotation about the given axis), as measured by the controller's gyroscope.

Returns Vector3.zero if GvrControllerInput is uninitialized. The controller's axes are:

  • X points to the right,
  • Y points perpendicularly up from the controller's top surface
  • Z lies along the controller's body, pointing towards the front

HomeButtonDown

static bool HomeButtonDown

Returns true in the frame the user starts pressing down the dominant controller's system button.

Returns false if GvrControllerInput is uninitialized.

HomeButtonState

static bool HomeButtonState

Returns true while the user holds down the dominant controller's system button.

Returns false if GvrControllerInput is uninitialized.

IsCharging

static bool IsCharging

Returns true if the dominant controller is currently being charged.

Returns false if GvrControllerInput is uninitialized.

IsTouching

static bool IsTouching

Returns true while the user is touching the dominant controller's touchpad.

Returns false if GvrControllerInput is uninitialized.

OnDevicesChanged

static Action OnDevicesChanged

Event handler for when controller devices have changed.

Any code that stores a GvrControllerInputDevice should get a new device instance from GetDevice. Existing GvrControllerInputDevices will be marked invalid and will log errors when used. Event handlers are called immediately when added.

OnStateChanged

static OnStateChangedEvent OnStateChanged

Event handler for when the connection state of the dominant controller changes.

Orientation

static Quaternion Orientation

Returns the dominant controller's current orientation in space, as a quaternion.

Returns Quaternion.identity if GvrControllerInput is uninitialized. The rotation is provided in 'orientation space' which means the rotation is given relative to the last time the user recentered their controllers. To make a game object in your scene have the same orientation as the dominant controller, simply assign this quaternion to the object's transform.rotation. To match the relative rotation, use transform.localRotation instead.

Recentered

static bool Recentered

Returns true if the user just completed the recenter gesture.

Returns false if GvrControllerInput is uninitialized. The headset and the dominant controller's orientation are now being reported in the new recentered coordinate system. This is an event flag (it is true for only one frame after the event happens, then reverts to false).

Recentering

static bool Recentering

State

static GvrConnectionState State

Returns the dominant controller's current connection state.

Returns GvrConnectionState.Error if GvrControllerInput is uninitialized.

StatePtr

static IntPtr StatePtr

Returns the GVR C library controller state pointer (gvr_controller_state*) for the dominant controller.

Returns IntPtr.Zero if GvrControllerInput is uninitialized.

SupportsBatteryStatus

static bool SupportsBatteryStatus

Returns true if battery status is supported.

Returns false if GvrControllerInput is uninitialized.

TouchDown

static bool TouchDown

Returns true in the frame the user starts touching the dominant controller's touchpad.

Returns false if GvrControllerInput is uninitialized. Every TouchDown event is guaranteed to be followed by exactly one TouchUp event in a later frame. Also, TouchDown and TouchUp will never both be true in the same frame.

TouchPos

static Vector2 TouchPos

Position of the dominant controller's current touch, if touching the touchpad.

Returns Vector2(0.5f, 0.5f) if GvrControllerInput is uninitialized. 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.

TouchPosCentered

static Vector2 TouchPosCentered

Position of the dominant controller's current touch, if touching the touchpad.

Returns Vector2.zero if GvrControllerInput is uninitialized. If not touching, this is the position of the last touch (when the finger left the touchpad). The X and Y range is from -1 to 1. (-.707,-.707) is bottom left, (.707,.707) is upper right. (0, 0) is the center of the touchpad. The magnitude of the touch vector is guaranteed to be <= 1.

TouchUp

static bool TouchUp

Returns true the frame after the user stops touching the dominant controller's touchpad.

Returns false if GvrControllerInput is uninitialized. Every TouchUp event is guaranteed to be preceded by exactly one TouchDown event in an earlier frame. Also, TouchDown and TouchUp will never both be true in the same frame.

Public attributes

emulatorConnectionMode

EmulatorConnectionMode emulatorConnectionMode = EmulatorConnectionMode.USB

Indicates how we connect to the controller emulator.

Public functions

OnStateChangedEvent

delegate void OnStateChangedEvent(
  GvrConnectionState state,
  GvrConnectionState oldState
)

Event handler for when the connection state of a controller changes.

Public static functions

GetDevice

GvrControllerInputDevice GetDevice(
  GvrControllerHand hand
)

Returns a controller device for the specified hand.