/// <summary> /// Check whether the given control is considered pressed according to the button press threshold. /// </summary> /// <param name="control">Control to check.</param> /// <param name="buttonPressPoint">Optional custom button press point. If not supplied, <see cref="InputSettings.defaultButtonPressPoint"/> /// is used.</param> /// <returns>True if the actuation of the given control is high enough for it to be considered pressed.</returns> /// <exception cref="ArgumentNullException"><paramref name="control"/> is <c>null</c>.</exception> /// <remarks> /// This method checks the actuation level of the control as <see cref="IsActuated"/> does. For <see cref="Controls.ButtonControl"/>s /// and other <c>float</c> value controls, this will effectively check whether the float value of the control exceeds the button /// point threshold. Note that if the control is an axis that can be both positive and negative, the press threshold works in /// both directions, i.e. it can be crossed both in the positive direction and in the negative direction. /// </remarks> /// <seealso cref="IsActuated"/> /// <seealso cref="InputSettings.defaultButtonPressPoint"/> /// <seealso cref="InputSystem.settings"/> public static bool IsPressed(this InputControl control, float buttonPressPoint = 0) { if (control == null) { throw new ArgumentNullException(nameof(control)); } if (Mathf.Approximately(0, buttonPressPoint)) { buttonPressPoint = InputSystem.settings.defaultButtonPressPoint; } return(control.IsActuated(buttonPressPoint)); }
/// <summary> /// Check whether the given control is considered pressed according to the button press threshold. /// </summary> /// <param name="control">Control to check.</param> /// <param name="buttonPressPoint">Optional custom button press point. If not supplied, <see cref="InputSettings.defaultButtonPressPoint"/> /// is used.</param> /// <returns>True if the actuation of the given control is high enough for it to be considered pressed.</returns> /// <exception cref="ArgumentNullException"><paramref name="control"/> is <c>null</c>.</exception> /// <remarks> /// This method checks the actuation level of the control as <see cref="IsActuated"/> does. For <see cref="Controls.ButtonControl"/>s /// and other <c>float</c> value controls, this will effectively check whether the float value of the control exceeds the button /// point threshold. Note that if the control is an axis that can be both positive and negative, the press threshold works in /// both directions, i.e. it can be crossed both in the positive direction and in the negative direction. /// </remarks> /// <seealso cref="IsActuated"/> /// <seealso cref="InputSettings.defaultButtonPressPoint"/> /// <seealso cref="InputSystem.settings"/> public static bool IsPressed(this InputControl control, float buttonPressPoint = 0) { if (control == null) { throw new ArgumentNullException(nameof(control)); } if (Mathf.Approximately(0, buttonPressPoint)) { if (control is ButtonControl button) { buttonPressPoint = button.pressPointOrDefault; } else { buttonPressPoint = ButtonControl.s_GlobalDefaultButtonPressPoint; } } return(control.IsActuated(buttonPressPoint)); }