GvrControllerInput

Main entry point for the Daydream controller API.

Summary

To use this API, add this behavior to a GameObject in your scene, or use the GvrControllerMain prefab. There can only be one object with this behavior on your scene.

This is a singleton object.

To access the controller state, simply read the static properties of this class. For example, to know the controller's current orientation, use GvrControllerInput.Orientation.

Inheritance

Inherits from: MonoBehaviour

Public types

EmulatorConnectionMode enum

Events

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

Public attributes

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

Properties

Accel
static Vector3
Returns the controller's current acceleration in meters per second squared.
ApiStatus
static GvrControllerApiStatus
Returns the API status of the current controller state.
AppButton
static bool
Returns true while the user holds down the app button.
AppButtonDown
static bool
Returns true in the frame the user starts pressing down the app button.
AppButtonUp
static bool
Returns true the frame after the user stops pressing down the app button.
BatteryLevel
static GvrControllerBatteryLevel
Returns the controller's current battery charge level.
ClickButton
static bool
Returns true while the user holds down the click button (touchpad button).
ClickButtonDown
static bool
Returns true in the frame the user starts pressing down the click button.
ClickButtonUp
static bool
Returns true the frame after the user stops pressing down the click button.
ErrorDetails
static string
If State == GvrConnectionState.Error, this contains details about the error.
Gyro
static Vector3
Returns the 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 home button.
HomeButtonState
static bool
Returns true while the user holds down the home button.
IsCharging
static bool
Returns true if the controller is currently being charged.
IsTouching
static bool
Returns true while the user is touching the touchpad.
Orientation
static Quaternion
Returns the 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 controller's current connection state.
StatePtr
static IntPtr
SupportsBatteryStatus
static bool
Returns true if battery status is supported.
TouchDown
static bool
Returns true in the frame the user starts touching the touchpad.
TouchPos
static Vector2
Position of the current touch, if touching the touchpad.
TouchPosCentered
static Vector2
Position of the current touch, if touching the touchpad.
TouchUp
static bool
Returns true the frame after the user stops touching the touchpad.

Public functions

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

Public types

EmulatorConnectionMode

 EmulatorConnectionMode

Events

OnControllerInputUpdated

static Action OnControllerInputUpdated

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

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.

OnStateChanged

static OnStateChangedEvent OnStateChanged

Public attributes

emulatorConnectionMode

EmulatorConnectionMode emulatorConnectionMode = EmulatorConnectionMode.USB

Indicates how we connect to the controller emulator.

Properties

Accel

static Vector3 Accel

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

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 API status of the current controller state.

AppButton

static bool AppButton

Returns true while the user holds down the app button.

AppButtonDown

static bool AppButtonDown

Returns true in the frame the user starts pressing down the app button.

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 app button.

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 controller's current battery charge level.

ClickButton

static bool ClickButton

Returns true while the user holds down the click button (touchpad button).

ClickButtonDown

static bool ClickButtonDown

Returns true in the frame the user starts pressing down the click button.

(touchpad button). 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 click button.

(touchpad button). 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 State == GvrConnectionState.Error, this contains details about the error.

Gyro

static Vector3 Gyro

Returns the 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.

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 home button.

HomeButtonState

static bool HomeButtonState

Returns true while the user holds down the home button.

IsCharging

static bool IsCharging

Returns true if the controller is currently being charged.

IsTouching

static bool IsTouching

Returns true while the user is touching the touchpad.

Orientation

static Quaternion Orientation

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

The rotation is provided in 'orientation space' which means the rotation is given relative to the last time the user recentered their controller. To make a game object in your scene have the same orientation as the 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.

The headset and the 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 controller's current connection state.

StatePtr

static IntPtr StatePtr

SupportsBatteryStatus

static bool SupportsBatteryStatus

Returns true if battery status is supported.

TouchDown

static bool TouchDown

Returns true in the frame the user starts touching the touchpad.

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 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.

TouchPosCentered

static Vector2 TouchPosCentered

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 -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 touchpad.

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 functions

OnStateChangedEvent

delegate void OnStateChangedEvent(
  GvrConnectionState state,
  GvrConnectionState oldState
)

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