-
-
Save fuqunaga/83bc7d964f40cb5eebea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[System.Serializable] | |
public class RandFloat : Rand<float> | |
{ | |
public RandFloat(float min, float max) : base(min, max){ } | |
protected override float _rand(float min, float max) { return UnityEngine.Random.Range(min, max); } | |
} | |
[System.Serializable] | |
public class RandInt : Rand<int> | |
{ | |
public RandInt(int min, int max) : base(min, max){ } | |
protected override int _rand(int min, int max) { return UnityEngine.Random.Range(min, max+1); } | |
} | |
public abstract class Rand<T> where T: struct | |
{ | |
public T _min; | |
public T _max; | |
T? _value; | |
public T value { get { return _value ?? Calc(); } } | |
public Rand() { } | |
public Rand(T min, T max) { _min = min; _max = max; } | |
public T Calc() | |
{ | |
_value = _rand(_min, _max); | |
return _value.Value; | |
} | |
protected abstract T _rand(T min, T max); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment