forked from Shardstone/trail-into-darkness
Added a bunch of utilities and modfief the character data structue
This commit is contained in:
45
Packages/com.jovian.utilties/Runtime/FloatRange.cs
Normal file
45
Packages/com.jovian.utilties/Runtime/FloatRange.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Jovian.Utilities {
|
||||
|
||||
public abstract class NumberRange<T> {
|
||||
public T min;
|
||||
public T max;
|
||||
|
||||
public abstract float Lerp(float t);
|
||||
public abstract float LerpUnclamped(float t);
|
||||
// returns 0 to 1
|
||||
public abstract float InverseLerp(float t);
|
||||
// returns values -1 to 1
|
||||
public abstract float InverseLerpSigned(float t);
|
||||
public abstract T Random();
|
||||
}
|
||||
|
||||
|
||||
[Serializable]
|
||||
public class FloatRange : NumberRange<float> {
|
||||
public FloatRange(float min, float max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
public override float Lerp(float t) => Mathf.Lerp(min, max, t);
|
||||
public override float LerpUnclamped(float t) => Mathf.LerpUnclamped(min, max, t);
|
||||
public override float InverseLerp(float t) => Mathf.InverseLerp(min, max, t);
|
||||
public override float InverseLerpSigned(float t) => Mathf.InverseLerp(min, max, t) * 2f - 1f;
|
||||
public override float Random() => UnityEngine.Random.Range(min, max);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class IntRange : NumberRange<int> {
|
||||
public IntRange(int min, int max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
public override float Lerp(float t) => Mathf.Lerp(min, max, t);
|
||||
public override float LerpUnclamped(float t) => Mathf.LerpUnclamped(min, max, t);
|
||||
public override float InverseLerp(float t) => Mathf.InverseLerp(min, max, t);
|
||||
public override float InverseLerpSigned(float t) => Mathf.InverseLerp(min, max, t) * 2f - 1f;
|
||||
public override int Random() => UnityEngine.Random.Range(min, max);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user