30 lines
756 B
C#
30 lines
756 B
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
public static class FloatExtensions
|
|
{
|
|
/// <summary>
|
|
/// Refrence link: https://forum.unity.com/attachments/upload_2021-1-14_13-8-33-png.773578/
|
|
/// </summary>
|
|
public static float Remap(this float from, float fromMin, float fromMax, float toMin, float toMax)
|
|
{
|
|
var fromAbs = from - fromMin;
|
|
var fromMaxAbs = fromMax - fromMin;
|
|
|
|
var normal = fromAbs / fromMaxAbs;
|
|
|
|
var toMaxAbs = toMax - toMin;
|
|
var toAbs = toMaxAbs * normal;
|
|
|
|
var to = toAbs + toMin;
|
|
|
|
return to;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Just clamps the value between two numbers (Easier to write)
|
|
/// </summary>
|
|
public static float Clamp(this float input, float min, float max) => Math.Clamp(input, min, max);
|
|
}
|