using UnityEngine; namespace UnityAtoms { /// /// None generic base class for `AtomReference<T, V>`. /// public abstract class AtomReference { /// /// Enum for how to use the Reference. /// public enum Usage { Value = 0, Constant = 1, Variable = 2, } /// /// Should we use the provided value (via inspector), the Constant value or the Variable value? /// [SerializeField] protected Usage _usage; } public abstract class AtomReference : AtomReference where V : AtomBaseVariable where C : AtomBaseVariable { /// /// Value used if `Usage` is set to `Value`. /// [SerializeField] private T _value; /// /// Constant used if `Usage` is set to `Constant`. /// public C _constant; /// /// Variable used if `Usage` is set to `Variable`. /// public V _variable; protected AtomReference() { _usage = AtomReference.Usage.Value; } protected AtomReference(T value) : this() { _usage = AtomReference.Usage.Value; _value = value; } /// /// Get the value for the Reference. /// /// The value of type `T`. public T Value { get { switch (_usage) { case (AtomReference.Usage.Constant): return _constant.Value; case (AtomReference.Usage.Variable): return _variable.Value; case (AtomReference.Usage.Value): default: return _value; } } } public static implicit operator T(AtomReference reference) { return reference.Value; } } }