Last active
May 6, 2018 16:43
-
-
Save rstecca/eeddcca026d68cf0c3af79d9702cb62f to your computer and use it in GitHub Desktop.
C# one-line getters to catch Vive cotrollers
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
/* * * * * * * * | |
PUT THESE AS CLASS MEMBERS | |
* * * * * * * * */ | |
SteamVR_Controller.Device _leftController; | |
private SteamVR_Controller.Device leftcontroller | |
{ | |
get | |
{ | |
return _leftController ?? ((SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.FarthestLeft) == -1) ? null : _leftController = SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.FarthestLeft))); | |
} | |
} | |
SteamVR_Controller.Device _rightController; | |
private SteamVR_Controller.Device rightcontroller | |
{ | |
get | |
{ | |
return _rightController ?? (((SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.FarthestRight)) == -1) ? null : _rightController = SteamVR_Controller.Input((SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.FarthestRight)))); | |
} | |
} | |
/* * * * * * * * * EXAMPLE OF USE IN UPDATE | |
void Update () | |
{ | |
//if (leftcontroller.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) | |
if(leftcontroller != null) | |
{ | |
if (leftcontroller.GetPressDown(EVRButtonId.k_EButton_Grip)) | |
{ | |
Debug.Log(string.Format("{0}", EVRButtonId.k_EButton_Grip.ToString())); | |
} | |
if (leftcontroller.GetPressDown(EVRButtonId.k_EButton_Axis0)) | |
{ | |
Vector2 axispos = leftcontroller.GetAxis(EVRButtonId.k_EButton_Axis0); | |
Debug.Log(string.Format("{0} : axis0 - {1}", axispos, EVRButtonId.k_EButton_Axis0.ToString())); | |
} | |
if (leftcontroller.GetPressDown(EVRButtonId.k_EButton_Axis1)) | |
{ | |
Vector2 axispos = leftcontroller.GetAxis(EVRButtonId.k_EButton_Axis1); | |
Debug.Log(string.Format("{0} : axis1 - {1}", axispos, EVRButtonId.k_EButton_Axis1.ToString())); | |
} | |
if (leftcontroller.GetPressDown(EVRButtonId.k_EButton_Axis2)) | |
{ | |
Vector2 axispos = leftcontroller.GetAxis(EVRButtonId.k_EButton_Axis2); | |
Debug.Log(string.Format("{0} : axis2 - {1}", axispos, EVRButtonId.k_EButton_Axis2.ToString())); | |
} | |
if (leftcontroller.GetPressDown(EVRButtonId.k_EButton_Axis3)) | |
{ | |
Vector2 axispos = leftcontroller.GetAxis(EVRButtonId.k_EButton_Axis3); | |
Debug.Log(string.Format("{0} : axis3 - {1}", axispos, EVRButtonId.k_EButton_Axis3.ToString())); | |
} | |
if (leftcontroller.GetPressDown(EVRButtonId.k_EButton_Axis4)) | |
{ | |
Vector2 axispos = leftcontroller.GetAxis(EVRButtonId.k_EButton_Axis4); | |
Debug.Log(string.Format("{0} : axis4 - {1}", axispos, EVRButtonId.k_EButton_Axis4.ToString())); | |
} | |
if (leftcontroller.GetPressDown(EVRButtonId.k_EButton_DPad_Left)) | |
{ | |
Vector2 axispos = leftcontroller.GetAxis(EVRButtonId.k_EButton_DPad_Left); | |
Debug.Log(string.Format("{0}", EVRButtonId.k_EButton_DPad_Left.ToString())); | |
} | |
if (leftcontroller.GetPressDown(EVRButtonId.k_EButton_DPad_Right)) | |
{ | |
Vector2 axispos = leftcontroller.GetAxis(EVRButtonId.k_EButton_DPad_Right); | |
Debug.Log(string.Format("{0}", EVRButtonId.k_EButton_DPad_Right.ToString())); | |
} | |
} | |
else | |
{ | |
Debug.LogWarning("No controllers connected"); | |
} | |
} | |
* * * * * * * * * * * * * * * * */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment