Skip to content

Instantly share code, notes, and snippets.

@lyokato
Created May 23, 2018 03:16
Show Gist options
  • Save lyokato/b8494c3923c36a8e55f07d07304f117e to your computer and use it in GitHub Desktop.
Save lyokato/b8494c3923c36a8e55f07d07304f117e to your computer and use it in GitHub Desktop.
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace OVROSX {
[RequireComponent(typeof(JoyconManager))]
public class JoyconTracker : MonoBehaviour {
public static JoyconTracker Instance { get; private set; }
private void Awake()
{
// Only allow one instance at runtime.
if (Instance != null)
{
enabled = false;
DestroyImmediate(this);
return;
}
Instance = this;
}
#if UNITY_EDITOR_OSX
private bool triggered = false;
// Update is called once per frame
private List<Joycon> joycons;
private Joycon joyconL;
private Joycon joyconR;
private Quaternion quatR;
private Quaternion quatL;
void Start() {
joycons = JoyconManager.Instance.j;
if (joycons == null || joycons.Count <= 0) return;
joyconL = joycons.Find(c => c.isLeft);
if (joyconL == null) {
Debug.LogWarning("Joycon (L) not found");
}
joyconR = joycons.Find(c => !c.isLeft);
if (joyconR == null) {
Debug.LogWarning("Joycon (R) not found");
}
}
void Update () {
if (joyconR.GetButton(Joycon.Button.SHOULDER_2)) {
triggered = true;
} else {
triggered = false;
}
quatL = joyconL.GetVector();
quatR = joyconR.GetVector();
}
public bool GetTriggerState() {
return triggered;
}
public Quaternion GetRightOrientation() {
return quatR;
}
public Quaternion GetLeftOrientation() {
return quatL;
}
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment