Created
June 15, 2019 03:07
-
-
Save DraconInteractive/bcd7ef80ca1f5dec3899b09072ab734a to your computer and use it in GitHub Desktop.
Easy reference for Oculus Quest Unity Input
This file contains hidden or 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
public class OVRInputSet | |
{ | |
public Vector2 leftStick, rightStick; | |
public float leftTrigger, rightTrigger; | |
public float leftHand, rightHand; | |
float lastLeftP, lastRightP, lastLeftH, lastRightH; | |
public void GetInput () | |
{ | |
leftStick = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.LTouch); | |
rightStick = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.RTouch); | |
leftTrigger = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, OVRInput.Controller.LTouch); | |
rightTrigger = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, OVRInput.Controller.RTouch); | |
leftHand = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.LTouch); | |
rightHand = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.RTouch); | |
lastLeftP = leftTrigger; | |
lastRightP = rightTrigger; | |
lastLeftH = leftHand; | |
lastRightH = rightHand; | |
} | |
public void GetInput(OVREventSet events) | |
{ | |
leftStick = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.LTouch); | |
rightStick = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.RTouch); | |
leftTrigger = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, OVRInput.Controller.LTouch); | |
rightTrigger = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, OVRInput.Controller.RTouch); | |
leftHand = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.LTouch); | |
rightHand = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.RTouch); | |
float b = 0.95f; | |
if (leftTrigger > b && lastLeftP <= b) | |
{ | |
events.onLeftTriggerDown?.Invoke(); | |
} | |
if (rightTrigger > b && lastRightP <= b) | |
{ | |
events.onRightTriggerDown?.Invoke(); | |
} | |
if (leftHand > b && lastLeftH <= b) | |
{ | |
events.onLeftHandDown?.Invoke(); | |
} | |
if (rightHand > b && lastRightH <= b) | |
{ | |
events.onRightHandDown?.Invoke(); | |
} | |
float bb = 0.05f; | |
if (leftTrigger < bb && lastLeftP >= bb) | |
{ | |
events.onLeftTriggerUp?.Invoke(); | |
} | |
if (rightTrigger < bb && lastRightP >= bb) | |
{ | |
events.onRightTriggerUp?.Invoke(); | |
} | |
if (leftHand < bb && lastLeftH >= bb) | |
{ | |
events.onLeftHandUp?.Invoke(); | |
} | |
if (rightHand < bb && lastRightH >= bb) | |
{ | |
events.onRightHandUp?.Invoke(); | |
} | |
if (OVRInput.GetDown(OVRInput.Button.One)) | |
{ | |
//A | |
events.onLeftTriggerDown?.Invoke(); | |
} | |
if (OVRInput.GetDown(OVRInput.Button.Two)) | |
{ | |
//B | |
events.onLeftTriggerDown?.Invoke(); | |
} | |
if (OVRInput.GetDown(OVRInput.Button.Three)) | |
{ | |
//X? | |
events.onLeftTriggerDown?.Invoke(); | |
} | |
if (OVRInput.GetDown(OVRInput.Button.Four)) | |
{ | |
//Y? | |
events.onLeftTriggerDown?.Invoke(); | |
} | |
lastLeftP = leftTrigger; | |
lastRightP = rightTrigger; | |
lastLeftH = leftHand; | |
lastRightH = rightHand; | |
} | |
} | |
[System.Serializable] | |
public class OVREventSet | |
{ | |
public UnityEvent onA, onB, onX, onY; | |
public UnityEvent onLeftTriggerDown, onRightTriggerDown, onLeftHandDown, onRightHandDown; | |
public UnityEvent onLeftTriggerUp, onRightTriggerUp, onLeftHandUp, onRightHandUp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment