# Getting started with experimental 6DoF controllers in Unity

This guide gives you high-level instructions for setting up Google VR
development with Unity and building a demo Daydream app that works with the
[experimental 6DoF controllers](https://developers.google.com/vr/experimental/6dof-controllers) and faceplate
for the Lenovo Mirage Solo with Daydream.

## Set up your development environment

Hardware requirements:

- [Lenovo Mirage Solo](https://developers.google.com/vr/discover/daydream-standalone) with Daydream

- Experimental Daydream 6DoF controllers
  [developer kit](https://developers.google.com/vr/experimental/6dof-controllers)

Software requirements:

- Unity [LTS release 2017.4](https://unity3d.com/unity/qa/lts-releases)
  or newer with **Android Build Support**.

- The latest `GoogleVRForUnity_*.unitypackage` from the
  [releases page](https://github.com/googlevr/gvr-unity-sdk/releases).

For more detailed installation instructions, see
[Quickstart for Google VR SDK for Unity with Android](https://developers.google.com/vr/develop/unity/get-started-android).

### Using the controllers after setup

Fluorescent lighting and HTC Vive Lighthouses are both known to interfere with tracking. Turn off the Vive Lighthouse if you have one, or move to a room with different conditions.

## Beta APIs

> [!WARNING]
> **Warning:** Beta APIs in the `GoogleVR.Beta` namespace are not subject to the usual deprecation processes. Beta APIs are expected to change and might be removed entirely in a future version without warning.

### Getting started with the experimental 6DoF controllers

> [!NOTE]
> **Note:** For general information about Daydream controller support in Unity, see the [Daydream (3DoF) controller](https://developers.google.com/vr/develop/unity/controller-support) documentation.

## Hello6DoFControllers demo scene

The **Hello6DoFControllers** demo scene included in the SDK demonstrates new
experimental 6DoF controller features:

- Demonstrates use of two controllers. The `DemoInputManager` script switches the laser pointer to the controller on button down of `TouchPadButton`, `Trigger`, `Grip`, or `App`.
- The `DemoObjectController6DoF` component demonstrates usage of the experimental 6DoF controller's grip button to "grab" a floating object.
- The **GvrBetaControllerPointer** prefab uses the `GvrBetaControllerVisualMulti` component to switch controller meshes at runtime and change controller transparency based on positional tracking status.

To try this demo scene:

1. [Create a new Unity project](https://developers.google.com/vr/develop/unity/get-started-android#create_a_new_unity_project_and_import_the_google_vr_unity_package).
2. Switch your project's Build Platform to **Android**.
3. Configure Unity build and player settings:

   | Setting | Value |
   |---|---|
   | **Player Settings** \> **XR Settings** \> **Virtual Reality Supported** | Enabled |
   | **Player Settings** \> **Other Settings** \> **SDKs** | Click **+** and select **Daydream** |
   | **Player Settings** \> **Android** \> **XR Settings** \> **Virtual Reality SDKs** \> **Daydream** \> **Positional Head Tracking** | Required |
   | **Player Settings** \> **Other Settings** \> **Minimum API Level** | **Android 7.1.1 'Nougat' (API level 25) or higher** or higher |
   | **Player Settings** \> **Other Settings** \> **Package Name** | Your app's package identifier |

4. Import the Google VR SDK for Unity (`GoogleVRForUnity_*.unitypackage`) that
   you downloaded above into your project.

5. In Unity, open the
   `GoogleVR/Beta/Demos/Hello6DoFControllers/Scenes/Hello6DoFControllers` scene.

6. Verify that the **Build Settings \> Scenes in Build** list is either empty, or
   contains only the currently open **Hello6DoFControllers** scene.

7. **Build and Run** the app on your device.

### Experimental 6DoF controller button mapping

For experimental 6DoF controllers, each button is mapped to either
`InputButton.Left` or `InputButton.Right`. As such, only `TouchPadButton` and
`Trigger` will trigger UI component pointer events:

| Controller button | Triggers UI component pointer events? | `PointerEventData.button` returns |
|---|---|---|
| `TouchPadButton` | **Yes** | `InputButton.Left` |
| `Trigger` | **Yes** | `InputButton.Left` |
| `App` | No | `InputButton.Right` |
| `Grip` | No | `InputButton.Right` |

### Controller emitted pointer events

Pointer events are handled differently, depending on whether you are using a
Daydream (3DoF) controller or experimental 6DoF controller.

> [!NOTE]
> **Note:** `PointerDown`, `PointerUp`, and `PointerClick` events do not support multiple simultaneous buttons down. Only the first button to go down will trigger the down event. Additional simultaneous button downs will be ignored until the first button to go down then goes up.

| Controller button | Emitted pointer events Daydream (3DoF) controllers | Emitted pointer events Experimental 6DoF controllers |
|---|---|---|
| `TouchPadButton` | `PointerDown`, `PointerUp`, `PointerClick` | `PointerDown`, `PointerUp`, `PointerClick` |
| `Trigger` | n/a | `PointerDown`, `PointerUp`, `PointerClick` |
| `Grip` | n/a | `PointerDown`, `PointerUp`, `PointerClick` |
| `App` | none | `PointerDown`, `PointerUp`, `PointerClick` |

### Accessing controller specific pointer event data

`PointerEventData` generated by Daydream (3DoF) controllers and experimental
6DoF controlers is of type `GvrPointerEventData` and contains additional event
information exposed through `PointerEventData` extension methods:

- `GvrGetButtonsDown()` returns the `GvrControllerButton` mask of buttons that went down to trigger the event
- `GvrGetControllerInputDevice()` returns the `GvrControllerInputDevice` that triggered the event

### Additional documentation

- [Unity User Manual](https://docs.unity3d.com/Manual/index.html) and [Scripting API Reference](https://docs.unity3d.com/ScriptReference/index.html).
- [Google VR SDK for Unity Developer docs](https://developers.google.com/vr/develop/unity/get-started-android) and [API reference](https://developers.google.com/vr/reference/unity)