/// <summary> /// Remap the specified value, from one range to another. /// </summary> /// <param name="value">The value to remap.</param> /// <param name="sourceRange">The source range to map from.</param> /// <param name="targetRange">The target range to map to.</param> public static float Remap(float value, InputRange sourceRange, InputRange targetRange) { if (sourceRange.Excludes(value)) { return(0.0f); } var sourceValue = Mathf.inverseLerp(sourceRange.Value0, sourceRange.Value1, value); return(Mathf.lerp(targetRange.Value0, targetRange.Value1, sourceValue)); }
public float MapValue(float value) { if (Raw) { value = value * Scale; value = SourceRange.Excludes(value) ? 0.0f : value; } else { // Scale value and clamp to a legal range. value = Mathf.clamp(value * Scale, -1.0f, 1.0f); // Remap from source range to target range. value = InputRange.Remap(value, SourceRange, TargetRange); } if (Invert) { value = -value; } return(value); }