public static HVRButtonState GetButtonState(HVRHandSide side, HVRButtons button) { var map = side == HVRHandSide.Right ? _rightButtonStates : _leftButtonStates; map.TryGetValue(button, out var state); return(state); }
protected void SetButtonState(HVRButtons button, ref HVRButtonState buttonState, bool pressed) { if (pressed) { if (!buttonState.Active) { buttonState.JustActivated = true; buttonState.Active = true; } } else { if (buttonState.Active) { buttonState.Active = false; buttonState.JustDeactivated = true; } } SetButtonState(Side, button, buttonState); }
protected override void CheckButtonState(HVRButtons button, ref HVRButtonState buttonState) { ResetButton(ref buttonState); switch (button) { case HVRButtons.Grip: buttonState.Value = Grip; if (!InputMap.GripUseAnalog) { SetButtonState(button, ref buttonState, GripButton); } if (InputMap.GripUseAnalog || InputMap.GripUseEither && !buttonState.Active) { SetButtonState(button, ref buttonState, Grip >= InputMap.GripThreshold); } break; case HVRButtons.Trigger: buttonState.Value = Trigger; if (InputMap.TriggerUseAnalog) { SetButtonState(button, ref buttonState, Trigger >= InputMap.TriggerThreshold); } else { SetButtonState(button, ref buttonState, TriggerButton); } break; case HVRButtons.Primary: SetButtonState(button, ref buttonState, PrimaryButton); break; case HVRButtons.PrimaryTouch: SetButtonState(button, ref buttonState, PrimaryTouch); break; case HVRButtons.Secondary: SetButtonState(button, ref buttonState, SecondaryButton); break; case HVRButtons.SecondaryTouch: SetButtonState(button, ref buttonState, SecondaryTouch); break; case HVRButtons.Menu: SetButtonState(button, ref buttonState, MenuButton); break; case HVRButtons.JoystickButton: SetButtonState(button, ref buttonState, JoystickClicked); break; case HVRButtons.TrackPadButton: SetButtonState(button, ref buttonState, TrackPadClicked); break; case HVRButtons.JoystickTouch: SetButtonState(button, ref buttonState, JoystickTouch); break; case HVRButtons.TrackPadTouch: SetButtonState(button, ref buttonState, TrackPadTouch); break; case HVRButtons.TriggerTouch: SetButtonState(button, ref buttonState, TriggerTouch); break; case HVRButtons.ThumbTouch: SetButtonState(button, ref buttonState, ThumbTouch); break; case HVRButtons.TriggerNearTouch: SetButtonState(button, ref buttonState, TriggerNearTouch); break; case HVRButtons.ThumbNearTouch: SetButtonState(button, ref buttonState, ThumbNearTouch); break; case HVRButtons.TrackPadLeft: SetButtonState(button, ref buttonState, TrackPadClicked && TrackpadAxis.x <= -InputMap.Axis2DLeftThreshold); break; case HVRButtons.TrackPadRight: SetButtonState(button, ref buttonState, TrackPadClicked && TrackpadAxis.x >= InputMap.Axis2DRighThreshold); break; case HVRButtons.TrackPadUp: SetButtonState(button, ref buttonState, TrackPadClicked && TrackpadAxis.y >= InputMap.Axis2DUpThreshold); break; case HVRButtons.TrackPadDown: SetButtonState(button, ref buttonState, TrackPadClicked && TrackpadAxis.y <= -InputMap.Axis2DDownThreshold); break; default: throw new ArgumentOutOfRangeException(nameof(button), button, null); } }
public static void SetButtonState(HVRHandSide side, HVRButtons button, HVRButtonState state) { var map = side == HVRHandSide.Right ? _rightButtonStates : _leftButtonStates; map[button] = state; }
protected abstract void CheckButtonState(HVRButtons button, ref HVRButtonState buttonState);
protected override void CheckButtonState(HVRButtons button, ref HVRButtonState buttonState) { ResetButton(ref buttonState); if (!InputMap) { return; } var trackPadIsPrimary = InputMap.TrackPadAxis == InputAxes.Primary2DAxis; switch (button) { case HVRButtons.Grip: Device.TryGetFeatureValue(CommonUsages.grip, out Grip); buttonState.Value = Grip; SetButtonState(button, ref buttonState, Grip >= InputMap.GripThreshold); break; case HVRButtons.Trigger: Device.TryGetFeatureValue(CommonUsages.trigger, out Trigger); buttonState.Value = Trigger; SetButtonState(button, ref buttonState, Trigger >= InputMap.TriggerThreshold); break; case HVRButtons.Primary: SetButtonState(button, ref buttonState, IsPressed(Device, InputMap.Primary)); PrimaryButton = buttonState.Active; break; case HVRButtons.PrimaryTouch: SetButtonState(button, ref buttonState, IsPressed(Device, InputMap.PrimaryTouch)); PrimaryTouch = buttonState.Active; break; case HVRButtons.Secondary: SetButtonState(button, ref buttonState, IsPressed(Device, InputMap.Secondary)); SecondaryButton = buttonState.Active; break; case HVRButtons.SecondaryTouch: SetButtonState(button, ref buttonState, IsPressed(Device, InputMap.SecondaryTouch)); SecondaryTouch = buttonState.Active; break; case HVRButtons.Menu: SetButtonState(button, ref buttonState, IsPressed(Device, InputMap.Menu)); MenuButton = buttonState.Active; break; case HVRButtons.JoystickButton: SetButtonState(button, ref buttonState, IsPressed(Device, InputMap.JoystickButton)); JoystickClicked = buttonState.Active; break; case HVRButtons.TrackPadButton: SetButtonState(button, ref buttonState, IsPressed(Device, InputMap.TrackPadButton)); TrackPadClicked = buttonState.Active; break; case HVRButtons.JoystickTouch: SetButtonState(button, ref buttonState, IsPressed(Device, InputMap.JoystickTouch)); JoystickTouch = buttonState.Active; break; case HVRButtons.TrackPadTouch: SetButtonState(button, ref buttonState, IsPressed(Device, InputMap.TrackPadTouch)); TrackPadTouch = buttonState.Active; break; case HVRButtons.TriggerTouch: #if USING_XR_MANAGEMENT Device.TryGetFeatureValue(indexTouch, out TriggerTouch); #else Device.TryGetFeatureValue(legacyIndexTouch, out var temp); TriggerTouch = temp > 0f; #endif SetButtonState(button, ref buttonState, TriggerTouch); break; case HVRButtons.TrackPadLeft: SetButtonState(button, ref TrackPadLeft, IsPressed(Device, trackPadIsPrimary ? HVRXRInputFeatures.PrimaryAxis2DLeft : HVRXRInputFeatures.SecondaryAxis2DLeft)); break; case HVRButtons.TrackPadRight: SetButtonState(button, ref TrackPadRight, IsPressed(Device, trackPadIsPrimary ? HVRXRInputFeatures.PrimaryAxis2DRight : HVRXRInputFeatures.SecondaryAxis2DRight)); break; case HVRButtons.TrackPadUp: SetButtonState(button, ref TrackPadUp, IsPressed(Device, trackPadIsPrimary ? HVRXRInputFeatures.PrimaryAxis2DUp : HVRXRInputFeatures.SecondaryAxis2DUp)); break; case HVRButtons.TrackPadDown: SetButtonState(button, ref TrackPadDown, IsPressed(Device, trackPadIsPrimary ? HVRXRInputFeatures.PrimaryAxis2DDown : HVRXRInputFeatures.SecondaryAxis2DDown)); break; } }