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