How do you access the input Axes and Buttons in XR
Hi,
Looking at the documentation there seems to be a native wrapper for controller input in XR (which would make sense because there would be no point supporting controller tracking if you cant access the buttons using the same framework).
However I can't find any information on what the standard Axes and Button names to use are, all I can find are "Button ID" and "Axes ID" and the rest of the information seems to push me to use the official SDKs, which sort of defeats the point of having XR in the first place
Answer by vladibo · Jul 19, 2018 at 01:45 AM
https://docs.unity3d.com/Manual/OpenVRControllers.html
Then inside the app
// call every frame
InvokeSetUnsetEvents<PadClick>(ref _isLtTouchpadPressed, Input.GetButton(input.LeftTouchpadPress), ControllerSide.Left, _ltHand);
InvokeSetUnsetEvents<PadClick>(ref _isRtTouchpadPressed, Input.GetButton(input.RightTouchpadPress), ControllerSide.Right, _rtHand);
InvokeSetUnsetEvents<TriggerButton>(ref _isLtTriggerPressed, Input.GetButton(input.LeftTriggerPress), ControllerSide.Left, _ltHand);
InvokeSetUnsetEvents<TriggerButton>(ref _isRtTriggerPressed, Input.GetButton(input.RightTriggerPress), ControllerSide.Right, _rtHand);
InvokeSetUnsetEvents<ApplicationMenuButton>(ref _isLtAppMenuPressed, Input.GetButton(input.LeftAppMenuPress), ControllerSide.Left, _ltHand);
InvokeSetUnsetEvents<ApplicationMenuButton>(ref _isRtAppMenuPressed, Input.GetButton(input.RightAppMenuPress), ControllerSide.Right, _rtHand);
void InvokeSetUnsetEvents<TEvent>(ref bool hasBeenSetBefore, bool isSetNow, ControllerSide side, Transform controller) where TEvent : ControllerButton, new()
{
if (hasBeenSetBefore)
{
if (!isSetNow)
{
hasBeenSetBefore = false;
fire(new TEvent { Controller = controller, IsPressed = false, Side = side });
}
}
else if (isSetNow)
{
hasBeenSetBefore = true;
fire(new TEvent { Controller = controller, IsPressed = true, Side = side });
}
}
Your answer
Follow this Question
Related Questions
How do you build a string from user input? 0 Answers
Unity Input system not returning correct values for HTC Vive touchpad. 2 Answers
Do I need to use the Input Manager to register all input axes? 0 Answers
Input.GetAxis() for HTC Vive controller not working in build 1 Answer
Android error building player Error: No resource found that matches the given name 3 Answers