Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Daydream Controller plugin for HoloLens Pro Asset Sample01
using UnityEngine;
using System;
using System.Collections.Generic;
using WSAControllerPlugin;
public class DaydreamController : MonoBehaviour
{
public GameObject handheldControllerBridge;
public GameObject controllerDisplay;
private HandheldControllerBridge _controllerBridge;
private Transform player;
public Vector3 ControllerOffset = new Vector3(0.1f, -0.2f, 0.3f);
void Awake()
{
player = Camera.main.transform;
}
void Start()
{
_controllerBridge = handheldControllerBridge.GetComponent<HandheldControllerBridge>();
_controllerBridge.HomeBtnDown += HomeBtnDownHandler;
_controllerBridge.AutoConnect();
}
void Update()
{
Vector3 pos = player.TransformDirection(Vector3.forward + ControllerOffset);
controllerDisplay.transform.position = player.position + pos;
if (!_controllerBridge.IsCalibrationDelayActive)
{
Quaternion rot = _controllerBridge.GetRotation();
rot.z = 0;
controllerDisplay.transform.localRotation = rot;
}
else
{
controllerDisplay.transform.localRotation = Quaternion.identity;
}
}
private void HomeBtnDownHandler()
{
_controllerBridge.BeginControllerCalibration();
}
private void HomeBtnUpHandler()
{
_controllerBridge.CancelControllerCalibration();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment