Last active
July 21, 2020 02:35
-
-
Save yuujii/84b914505230a9bbdba7c7b63fc9a071 to your computer and use it in GitHub Desktop.
Google Daydream Controller plugin for HoloLens Pro Asset Sample01 #Unity #HoloLens
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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