Skip to content

TBDaydreamController

Holden Link edited this page Feb 19, 2017 · 38 revisions

Overview

A wrapper for the Daydream controller that allows you to emulate it with Oculus Touch or Steam VR (Vive) controllers in the editor or in PC builds.

Dependencies

Platform must be set using TBEditorBuildSettings tool.

TBDaydreamController and GvrController components must be added to a GameObject in your scene. Alternatively, both scripts can be added at runtime. They do not need to be on the same GameObject.

If using Steam VR, a TBSteamVRDeviceManager will automatically be added to handle Steam VR controller assignment.

To use in PC/Standalone, you may need to do a mass find and replace of the #if defs in the Google VR SDK to say #if DAYDREAM || FAKE_DAYDREAM.

Usage

Replacing GvrController References

Anywhere in your project that you would reference a function in Google's GvrController class should be swapped out with a reference to a function in TBDaydreamController.

Why doesn't it use the TBTrackedController system?

Because Daydream uses a one-handed controller without positional tracking, it's best to design separate controls for it if you plan on supporting it alongside other platforms. TBDaydreamController is meant for people developing for Daydream who just want to use Vive / Touch controllers for quick testing during development.

Reference

Input Functions

Buttons

Check if buttons are being pressed by passing a TBAVRInputType (ClickButton, AppButton, or Touchpad) through the following button functions:

Function       | Description
------------| ------------
`bool GetButtonDown(TBAVRInputType inputType)` | Returns true if the provided input type was pressed / touched.
`bool GetButtonUp(TBAVRInputType inputType)` | Returns true if the provided input type was released.
`bool GetButton(TBAVRInputType inputType)`  | Returns true if the provided input type is being pressed / touched.

Note: TButt treats the touchpad and click button as separate buttons. For example:
GetButtonDown(TBAVRInputType.Touchpad) will return true the frame that the touchpad was touched.
GetButtonDown(TBAVRInputType.ClickButton) will return true the frame that the touchpad's click button was pressed.

Tracking

The controller's tracking data can be accessed with the following functions:

Function                              | Description
--------------------------------------| ------------
`Quaternion GetRotation()`    | Replaces `GvrController.Orientation`
`Vector3 GetGyro()`  | Replaces `GvrController.Gyro`
`Vector3 GetAcceleration()`  | Replaces `GvrController.Accel`

Quaternion GetRawRotation() works the same as GetRotation() on Native Daydream, but returns raw controller rotation on Vive / Touch in case you need to access it for some reason.

Handedness

You can set and access the player's handedness preference through TBDaydreamController. On device, this handedness value is automatically updated from whatever the player has set it to in Daydream Home every time your game/app receives focus from Daydream Home.

Function | Description --------------------------------------| ------------ Handedness GetHandedness() | Returns Handedness.Left or Handedness.Right

Example Implementation

GvrController references in code

if(GvrController.ClickButtonUp)
     Debug.Log("Click button was released!");
if (GvrController.IsTouching)
      Debug.Log("Touchpad is being touched!");

Debug.Log("Matching controller's rotation...");
transform.rotation = GvrController.Orientation;

Replaced with references to TBDaydreamController

if (TBDaydreamController.GetButtonUp(TBAVRInputType.ClickButton))
     Debug.Log("Click button was released!");
if (TBDaydreamController.GetButton(TBAVRInputType.Touchpad))
     Debug.Log("Touchpad is being touched!");

Debug.Log("Matching controller's rotation...");
transform.rotation = TBDaydreamController.GetRotation();

Events

You can interface with TBDaydreamController using events instead of checking button states in an update loop, if you prefer. Subscribe to them through TBDaydreamController.instance.

Event                    | Description
-------------------------| ------------
`OnTouchUp`              | Finger was raised off touchpad.
`OnTouchDown`            | Finger was placed on touchpad.
`OnClickButtonDown`      | Touchpad click button was pressed.
`OnClickButtonUp`        | Touchpad click button was released.
`OnAppButtonDown`        | App button was pressed.
`OnAppButtonUp`          | App button was released.
`OnAppButtonLongPress`   | App button was released after being held for more than a second. (adjust by changing `_longAppButtonPressTime`)
`OnAppButtonShortPress`  | App button was released in less than a second. (adjust by changing `_longAppButtonPressTime`)
`OnSwipe`                | Passes a `TBSwipeDirection` enum for every swipe.
`OnSwipeDown`            | Touchpad was swiped down.
`OnSwipeUp`              | Touchpad was swiped up.
`OnSwipeLeft`            | Touchpad was swiped left.
`OnSwipeRight`           | Touchpad was swiped right.

Emulator Button Mappings

Oculus Touch

AVRInput Oculus Touch
ClickButton Joystick button, A, or X
AppButton B or Y
Touchpad Touch joystick, A or X

HTC Vive

AVRInput HTC Vive
ClickButton Trackpad button
AppButton Menu Button
Touchpad Trackpad