No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClampProcessor.cs 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine.Scripting;
  2. ////TODO: move clamping settings into struct and add process function; then embed both here and in AxisControl
  3. namespace UnityEngine.InputSystem.Processors
  4. {
  5. /// <summary>
  6. /// Clamp a floating-point input to between <see cref="min"/> and <see cref="max"/>. This is equivalent
  7. /// to <c>Mathf.Clamp(value, min, max)</c>.
  8. /// </summary>
  9. /// <remarks>
  10. /// This processor is registered (see <see cref="InputSystem.RegisterProcessor{T}"/>) under the name "clamp" by default.
  11. ///
  12. /// Note that no normalization is performed. If you want to re-normalize the input value after clamping,
  13. /// add a <see cref="NormalizeProcessor"/>. Alternatively, add a <see cref="AxisDeadzoneProcessor"/> which
  14. /// both clamps and normalizes.
  15. ///
  16. /// <example>
  17. /// <code>
  18. /// </code>
  19. /// // Bind to right trigger on gamepad such that the value never drops below 0.3 and never goes
  20. /// // above 0.7.
  21. /// new InputAction(binding: "&lt;Gamepad&gt;/rightTrigger", processors: "clamp(min=0.3,max=0.7)");
  22. /// </example>
  23. /// </remarks>
  24. public class ClampProcessor : InputProcessor<float>
  25. {
  26. /// <summary>
  27. /// Minimum value (inclusive!) of the accepted value range.
  28. /// </summary>
  29. public float min;
  30. /// <summary>
  31. /// Maximum value (inclusive!) of the accepted value range.
  32. /// </summary>
  33. public float max;
  34. /// <summary>
  35. /// Clamp <paramref name="value"/> to the range of <see cref="min"/> and <see cref="max"/>.
  36. /// </summary>
  37. /// <param name="value">Input value.</param>
  38. /// <param name="control">Ignored.</param>
  39. /// <returns>Clamped value.</returns>
  40. public override float Process(float value, InputControl control)
  41. {
  42. return Mathf.Clamp(value, min, max);
  43. }
  44. /// <inheritdoc/>
  45. public override string ToString()
  46. {
  47. return $"Clamp(min={min},max={max})";
  48. }
  49. }
  50. }