Skip to content

Instantly share code, notes, and snippets.

@yuujii
Last active July 21, 2020 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuujii/84b914505230a9bbdba7c7b63fc9a071 to your computer and use it in GitHub Desktop.
Save yuujii/84b914505230a9bbdba7c7b63fc9a071 to your computer and use it in GitHub Desktop.
Google Daydream Controller plugin for HoloLens Pro Asset Sample01 #Unity #HoloLens
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