I created a game that uses Unity's OpenXR. I am trying to make the game compatible with both Oculus and HTC Vive.
In the code below, I am just trying to detect when the user presses their right primary button. This works just fine on Oculus, but I've gotten many Vive users who say that this doesn't work.
bool primary = false;
bool secondary = false;
bool trigger = false;
bool grip = false;
public InputDevice device;
void Start()
{
List<InputDevice> devices = new List<InputDevice>();
InputDevices.GetDevicesAtXRNode(XRNode.RightHand, devices);
device = devices[0];
}
public void Update(){
bool newGrip;
bool newTrigger;
bool newSecondary;
bool newPrimary;
device.TryGetFeatureValue(CommonUsages.gripButton, out newGrip);
device.TryGetFeatureValue(CommonUsages.triggerButton, out newTrigger);
device.TryGetFeatureValue(CommonUsages.secondaryButton, out newSecondary);
device.TryGetFeatureValue(CommonUsages.primaryButton, out newPrimary);
if (newGrip != grip)
{
if (newGrip)
{
//grip pressed
}
else
{
//grip released
}
grip = newGrip;
}
if (newTrigger != trigger)
{
if (newTrigger)
{
//trigger pressed
}
else
{
//trigger released
}
trigger = newTrigger;
}
if (newSecondary != secondary)
{
if (newSecondary)
{
//secondary pressed
}
else
{
//secondary released
}
secondary = newSecondary;
}
if (newPrimary != primary)
{
if (newPrimary)
{
//primary pressed
}
else
{
//primary released
}
primary = newPrimary;
}
}
Note that the triggers and grips get detected just fine on both HTC Vive and Oculus. The Secondary button isn't supported on Vive, so I'm assuming device.TryGetFeatureValue(CommonUsages.secondaryButton, out newSecondary) always returns false. It is just the primary button that is giving me an unexpected issue.
Now according to unity (https://docs.unity3d.com/Manual/xr_input.html), the Vive's primary button is supported.
Does anyone know why the above implementation wouldn't recognize the Vive's primary button being pressed? Also, is there any way to detect the menu button for Vive players with unity's OpenXR? The link above says the menu button is not supported, but having an extra button to work with would be useful.
Thank you in advance!