Hello. I have two classes called IntRange and FloatRange, which serve the only purpose of checking if a given number is withing the specified range.
[Serializable]
public sealed class IntRange : INumericRange<int>
{
const int DEFAULT_MIN = 0;
const int DEFAULT_MAX = 10;
public Vector2Int Limits => new(MinLimit, MaxLimit);
[field: SerializeField, HideInInspector] public Vector2 Range { get; private set; }
[field: SerializeField] public int MinLimit { get; private set; } = DEFAULT_MIN;
[field: SerializeField] public int MaxLimit { get; private set; } = DEFAULT_MAX;
[field: SerializeField] public int Min { get; private set; } = DEFAULT_MIN;
[field: SerializeField] public int Max { get; private set; } = DEFAULT_MAX;
public bool IsInRange(int value)
{
return value > Min && value < Max;
}
public bool IsInRangeInclusive(int value)
{
return value >= Min && value <= Max;
}
public static implicit operator bool(IntRange value) => value != null;
public static implicit operator Vector2Int(IntRange value) => Vector2Int.FloorToInt(value.Range);
}
The other class is the same but with floats.
For flexibility, I decided to make a PropertyDrawer for each of those clases so I can modify those values smoothly.