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{
  OFF,
  USB,
  WIFI
}
enum
Controller Emulatuor connection modes.

Public attributes

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

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
Deprecated. Replaced by GvrControllerInputDevice.Accel.
Gets the dominant controller's current acceleration in meters per second squared.
ApiStatus
static GvrControllerApiStatus
Gets the status of the controller API.
AppButton
static bool
Deprecated. Replaced by GvrControllerInputDevice.GetButton(GvrControllerButton.App).
Gets a value indicating whether the user is currently holding down the dominant controller's app button.
AppButtonDown
static bool
Deprecated. Replaced by GvrControllerInputDevice.GetButtonDown(GvrControllerButton.App).
Gets a value indicating whether this is the frame the user started pressing down the dominant controller's app button.
AppButtonUp
static bool
Deprecated. Replaced by GvrControllerInputDevice.GetButtonUp(GvrControllerButton.App).
Gets a value indicating whether this is the frame after the user stopped pressing down the dominant controller's app button.
BatteryLevel
static GvrControllerBatteryLevel
Deprecated. Replaced by GvrControllerInputDevice.BatteryLevel.
Gets the dominant controller's current battery charge level.
ClickButton
static bool
Deprecated. Replaced by GvrControllerInputDevice.GetButton(GvrControllerButton.TouchPadButton).
Gets a value indicating whether the user currently holds down the dominant controller's touchpad button.
ClickButtonDown
static bool
Deprecated. Replaced by GvrControllerInputDevice.GetButtonDown(GvrControllerButton.TouchPadButton).
Gets a value indicating whether this is the frame the user starts pressing down the dominant controller's touchpad button.
ClickButtonUp
static bool
Deprecated. Replaced by GvrControllerInputDevice.GetButtonUp(GvrControllerButton.TouchPadButton).
Gets a value indicating whether this is the frame after the user stops pressing down the dominant controller's touchpad button.
ErrorDetails
static string
Deprecated. Replaced by GvrControllerInputDevice.ErrorDetails.
Gets details about the reasoning behind the Dominant Controller's error state.
Gyro
static Vector3
Deprecated. Replaced by GvrControllerInputDevice.Gyro.
Gets the dominant controller's current angular speed in radians per second.
HomeButtonDown
static bool
Deprecated. Replaced by GvrControllerInputDevice.GetButtonDown(GvrControllerButton.System).
Gets a value indicating whether this is the frame the user started pressing down the dominant controller's system button.
HomeButtonState
static bool
Deprecated. Replaced by GvrControllerInputDevice.GetButton(GvrControllerButton.System).
Gets a value indicating whether the user is holding down the dominant controller's system button.
IsCharging
static bool
Deprecated. Replaced by GvrControllerInputDevice.IsCharging.
Gets a value indicating whether the dominant controller is currently being charged.
IsTouching
static bool
Deprecated. Replaced by GvrControllerInputDevice.GetButton(GvrControllerButton.TouchPadTouch).
Gets a value indicating whether 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
Deprecated. Replaced by GvrControllerInputDevice.Orientation.
Gets the dominant controller's current orientation in space, as a quaternion.
Recentered
static bool
Gets a value indicating whether the user just completed the recenter gesture.
Recentering
static bool
Deprecated. Use Recentered to detect when user has completed the recenter gesture.
Gets a value indicating whether the user is currently recentering.
State
static GvrConnectionState
Deprecated. Replaced by GvrControllerInputDevice.State.
Gets the dominant controller's current connection state.
StatePtr
static IntPtr
Deprecated. Replaced by GvrControllerInputDevice.StatePtr.
Gets the GVR C library controller state pointer (gvr_controller_state*) for the dominant controller.
SupportsBatteryStatus
static bool
Gets a value indicating whether battery status is supported.
TouchDown
static bool
Deprecated. Replaced by GvrControllerInputDevice.GetButtonDown(GvrControllerButton.TouchPadTouch).
Gets a value indicating whether this frame is the frame the user starts touching the dominant controller's touchpad.
TouchPos
static Vector2
Deprecated. Please migrate to the center-relative GvrControllerInputDevice.TouchPos.
Gets the position of the dominant controller's current touch, if touching the touchpad.
TouchPosCentered
static Vector2
Deprecated. Please migrate to the center-relative GvrControllerInputDevice.TouchPos.
Gets the position of the dominant controller's current touch, if touching the touchpad.
TouchUp
static bool
Deprecated. Replaced by GvrControllerInputDevice.GetButtonUp(GvrControllerButton.TouchPadTouch).
Gets a value indicating whether this frame is the frame after the user stops touching the dominant controller's touchpad.

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

Controller Emulatuor connection modes.

Properties
OFF

Emulator disconnected.

USB

Emulator connects over USB.

WIFI

Emulator connects over WIFI.

Public attributes

emulatorConnectionMode

EmulatorConnectionMode emulatorConnectionMode = EmulatorConnectionMode.USB

Indicates how to connect to the controller emulator.

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

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

Deprecated. Replaced by GvrControllerInputDevice.Accel.

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.

The acceleration. Will be Vector3.zero if GvrControllerInput is uninitialized.

ApiStatus

static GvrControllerApiStatus ApiStatus

Gets the status of the controller API.

Returns GvrControllerApiStatus.Error if GvrControllerInput is uninitialized.

The api status.

AppButton

static bool AppButton

Gets a value indicating whether the user is currently holding down the dominant controller's app button.

Deprecated. Replaced by GvrControllerInputDevice.GetButton(GvrControllerButton.App).

Returns false if GvrControllerInput is uninitialized.

Value true if the user is currently holding down the dominant controller's app button, false otherwise.

AppButtonDown

static bool AppButtonDown

Gets a value indicating whether this is the frame the user started pressing down the dominant controller's app button.

Deprecated. Replaced by GvrControllerInputDevice.GetButtonDown(GvrControllerButton.App).

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

Value true if this is the frame the user started pressing down the dominant controller's app button, false otherwise.

AppButtonUp

static bool AppButtonUp

Gets a value indicating whether this is the frame after the user stopped pressing down the dominant controller's app button.

Deprecated. Replaced by GvrControllerInputDevice.GetButtonUp(GvrControllerButton.App).

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.

Value true if this is the frame after the user stopped pressing down the dominant controller's app button, false otherwise.

BatteryLevel

static GvrControllerBatteryLevel BatteryLevel

Gets the dominant controller's current battery charge level.

Deprecated. Replaced by GvrControllerInputDevice.BatteryLevel.

Returns GvrControllerBatteryLevel.Error if GvrControllerInput is uninitialized.

The dominant controller's current battery charge level.

ClickButton

static bool ClickButton

Gets a value indicating whether the user currently holds down the dominant controller's touchpad button.

Deprecated. Replaced by GvrControllerInputDevice.GetButton(GvrControllerButton.TouchPadButton).

Returns false if GvrControllerInput is uninitialized.

Value true if the user currently holds down the dominant controller's touchpad button, false otherwise.

ClickButtonDown

static bool ClickButtonDown

Gets a value indicating whether this is the frame the user starts pressing down the dominant controller's touchpad button.

Deprecated. Replaced by GvrControllerInputDevice.GetButtonDown(GvrControllerButton.TouchPadButton).

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.

Value true this is the frame the user started pressing down the dominant controller's touchpad button, false otherwise.

ClickButtonUp

static bool ClickButtonUp

Gets a value indicating whether this is the frame after the user stops pressing down the dominant controller's touchpad button.

Deprecated. Replaced by GvrControllerInputDevice.GetButtonUp(GvrControllerButton.TouchPadButton).

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.

Value true if this is the frame after the user stops pressing down the dominant controller's touchpad button, false otherwise.

ErrorDetails

static string ErrorDetails

Gets details about the reasoning behind the Dominant Controller's error state.

Deprecated. Replaced by GvrControllerInputDevice.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.

Details about the reasoning behind the dominant controller's error state.

Gyro

static Vector3 Gyro

Gets the dominant controller's current angular speed in radians per second.

Deprecated. Replaced by GvrControllerInputDevice.Gyro.

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

The gyro's angular speed.

HomeButtonDown

static bool HomeButtonDown

Gets a value indicating whether this is the frame the user started pressing down the dominant controller's system button.

Deprecated. Replaced by GvrControllerInputDevice.GetButtonDown(GvrControllerButton.System).

Returns false if GvrControllerInput is uninitialized.

Value true if this is the frame the user started pressing down the dominant controller's system button, false otherwise.

HomeButtonState

static bool HomeButtonState

Gets a value indicating whether the user is holding down the dominant controller's system button.

Deprecated. Replaced by GvrControllerInputDevice.GetButton(GvrControllerButton.System).

Returns false if GvrControllerInput is uninitialized.

Value true if the user is holding down the dominant controller's system button, false otherwise.

IsCharging

static bool IsCharging

Gets a value indicating whether the dominant controller is currently being charged.

Deprecated. Replaced by GvrControllerInputDevice.IsCharging.

Returns false if GvrControllerInput is uninitialized.

Value true if the dominant controller is charging. Otherwise, false.

IsTouching

static bool IsTouching

Gets a value indicating whether the user is touching the dominant controller's touchpad.

Deprecated. Replaced by GvrControllerInputDevice.GetButton(GvrControllerButton.TouchPadTouch).

Returns false if GvrControllerInput is uninitialized.

Value true if is touching. Otherwise, false.

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

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

Deprecated. Replaced by GvrControllerInputDevice.Orientation.

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.

The orientation. This is Quaternion.identity if GvrControllerInput is uninitialized.

Recentered

static bool Recentered

Gets a value indicating whether 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).

Value true if the user has just finished recentering, false otherwise.

Recentering

static bool Recentering

Gets a value indicating whether the user is currently recentering.

Deprecated. Use Recentered to detect when user has completed the recenter gesture.

Value true if the user is currently recentering, false otherwise.

State

static GvrConnectionState State

Gets the dominant controller's current connection state.

Deprecated. Replaced by GvrControllerInputDevice.State.

Returns GvrConnectionState.Error if GvrControllerInput is uninitialized.

The state.

StatePtr

static IntPtr StatePtr

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

Deprecated. Replaced by GvrControllerInputDevice.StatePtr.

Returns IntPtr.Zero if GvrControllerInput is uninitialized.

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

SupportsBatteryStatus

static bool SupportsBatteryStatus

Gets a value indicating whether battery status is supported.

Returns false if GvrControllerInput is uninitialized.

Value true if the GVR Controller Input supports BatteryStatus calls, false otherwise.

TouchDown

static bool TouchDown

Gets a value indicating whether this frame is the frame the user starts touching the dominant controller's touchpad.

Deprecated. Replaced by GvrControllerInputDevice.GetButtonDown(GvrControllerButton.TouchPadTouch).

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.

Value true if this is the frame after the user starts touching the dominant controller's touchpad, false otherwise.

TouchPos

static Vector2 TouchPos

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

Deprecated. Please migrate to the center-relative GvrControllerInputDevice.TouchPos.

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.

The touch position.

TouchPosCentered

static Vector2 TouchPosCentered

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

Deprecated. Please migrate to the center-relative GvrControllerInputDevice.TouchPos.

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 less than or equal to 1.

The touch position centered.

TouchUp

static bool TouchUp

Gets a value indicating whether this frame is the frame after the user stops touching the dominant controller's touchpad.

Deprecated. Replaced by GvrControllerInputDevice.GetButtonUp(GvrControllerButton.TouchPadTouch).

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.

Value true if this is the frame after the user stops touching the dominant controller's touchpad, false otherwise.

Public functions

OnStateChangedEvent

delegate void OnStateChangedEvent(
  GvrConnectionState state,
  GvrConnectionState oldState
)

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

Details
Parameters
state
The new state.
oldState
The previous state.

Public static functions

GetDevice

GvrControllerInputDevice GetDevice(
  GvrControllerHand hand
)

Returns a controller device for the specified hand.

Details
Parameters
hand
The hand whose input device should be fetched.
Returns
The controller input device.