135 lines
No EOL
3.2 KiB
C#
135 lines
No EOL
3.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.XR;
|
|
|
|
[Serializable]
|
|
public class Control
|
|
{
|
|
[HideInInspector]
|
|
public Logic logic;
|
|
|
|
public OculusFilter oculusFilter;
|
|
public ValveFilter valveFilter;
|
|
|
|
public bool connected;
|
|
public Physical headset, leftHand, rightHand;
|
|
public Con offCon, mainCon;
|
|
|
|
public void Set(InspectorSetter setter)
|
|
{
|
|
oculusFilter.Set(setter);
|
|
valveFilter.Set(setter);
|
|
}
|
|
|
|
public void Fetch(InspectorSetter setter)
|
|
{
|
|
oculusFilter.Fetch(setter);
|
|
valveFilter.Fetch(setter);
|
|
}
|
|
|
|
public void Start(Logic logic)
|
|
{
|
|
this.logic = logic;
|
|
oculusFilter.Start(this);
|
|
valveFilter.Start(this);
|
|
|
|
headset.device = InputDevices.GetDeviceAtXRNode(XRNode.Head);
|
|
leftHand.device = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand);
|
|
rightHand.device = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
// General
|
|
connected = headset.device.isValid && (leftHand.device.isValid || rightHand.device.isValid);
|
|
if (!connected)
|
|
return;
|
|
|
|
|
|
XRDevice.DisableAutoXRCameraTracking(Camera.main, true);
|
|
|
|
headset.Update(logic.world.rig);
|
|
leftHand.Update(logic.world.rig);
|
|
rightHand.Update(logic.world.rig);
|
|
|
|
// handedness!
|
|
offCon.Update(leftHand, rightHand);
|
|
mainCon.Update(rightHand, leftHand);
|
|
|
|
// you can play with your left controller or your right (and?) RIG CLASS?
|
|
|
|
// Swappable Proprietary Overrides
|
|
oculusFilter.Update();
|
|
valveFilter.Update();
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class Physical
|
|
{
|
|
public InputDevice device;
|
|
public Vector3 pos, worldPos;
|
|
public Vector3 oldPos, oldWorldPos;
|
|
public Quaternion rot, oldRot, rotDelta;
|
|
|
|
public Vector3 vel, rotVel;
|
|
|
|
public void Update(Rig rig)
|
|
{
|
|
oldPos = pos; oldWorldPos = worldPos;
|
|
device.TryGetFeatureValue(CommonUsages.devicePosition, out pos);
|
|
worldPos = rig.rigTransform.position + pos;
|
|
oldRot = rot;
|
|
device.TryGetFeatureValue(CommonUsages.deviceRotation, out rot);
|
|
rotDelta = rot * Quaternion.Inverse(oldRot);
|
|
|
|
device.TryGetFeatureValue(CommonUsages.deviceVelocity, out vel);
|
|
device.TryGetFeatureValue(CommonUsages.deviceAngularVelocity, out rotVel);
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class Con
|
|
{
|
|
public Tactile triggerBtn, gripBtn;
|
|
public float trigger, grip, stretch;
|
|
public Vector2 joystick;
|
|
|
|
public void Update(Physical mainHand, Physical offHand)
|
|
{
|
|
mainHand.device.TryGetFeatureValue(CommonUsages.trigger, out trigger);
|
|
mainHand.device.TryGetFeatureValue(CommonUsages.grip, out grip);
|
|
mainHand.device.TryGetFeatureValue(CommonUsages.primary2DAxis, out joystick);
|
|
|
|
bool state;
|
|
mainHand.device.TryGetFeatureValue(CommonUsages.triggerButton, out state); // change to custom float check?
|
|
triggerBtn.Update(state);
|
|
mainHand.device.TryGetFeatureValue(CommonUsages.gripButton, out state);
|
|
gripBtn.Update(state);
|
|
|
|
stretch = Vector3.Distance(mainHand.pos, offHand.pos);
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class Tactile
|
|
{
|
|
public bool down, held, up;
|
|
|
|
public void Update(bool state)
|
|
{
|
|
down = up = false;
|
|
|
|
if (state && !held)
|
|
{
|
|
down = true;
|
|
}
|
|
|
|
if (!state && held)
|
|
{
|
|
up = true;
|
|
}
|
|
|
|
held = state;
|
|
}
|
|
} |