using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Serialization; namespace UnityAtoms { /// /// None generic base class for Variables. Inherits from `BaseAtom`. /// [EditorIcon("atom-icon-teal")] public abstract class AtomBaseVariable : BaseAtom { /// /// The Variable value as an `object`.abstract Beware of boxing! 🥊 /// /// The Variable value as an `object`. public abstract object BaseValue { get; set; } /// /// Abstract method that could be implemented to reset the Variable value. /// public abstract void Reset(bool shouldTriggerEvents = false); } /// /// Generic base class for Variables. Inherits from `AtomBaseVariable`. /// /// The Variable value type. [EditorIcon("atom-icon-teal")] public abstract class AtomBaseVariable : AtomBaseVariable { /// /// The Variable value as an `object`.abstract Beware of boxing! 🥊 /// /// The Variable value as an `object`. public override object BaseValue { get { return _value; } set { Value = (T)value; } } /// /// The Variable value as a property. /// /// Get or set the Variable value. public virtual T Value { get { return _value; } set { throw new NotImplementedException(); } } [FormerlySerializedAs("value")] [SerializeField] protected T _value; protected bool Equals(AtomBaseVariable other) { return EqualityComparer.Default.Equals(_value, other._value); } /// /// Determines equality between Variables. /// /// The other Variable to compare as an `object`. /// `true` if they are equal, otherwise `false`. public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; if (obj.GetType() != GetType()) return false; return Equals((AtomBaseVariable)obj); } /// /// Get an unique hash code for this Variable based on the Variable's value. /// /// public override int GetHashCode() { unchecked { return EqualityComparer.Default.GetHashCode(_value); } } /// /// Equal operator. /// /// The first Variable to compare. /// The second Variable to compare. /// `true` if eqaul, otherwise `false`. public static bool operator ==(AtomBaseVariable left, AtomBaseVariable right) { return Equals(left, right); } /// /// None equality operator. /// /// The first Variable to compare. /// The second Variable to compare. /// `true` if not eqaul, otherwise `false`. public static bool operator !=(AtomBaseVariable left, AtomBaseVariable right) { return !Equals(left, right); } /// /// Not implemented.abstract Throws Exception /// public override void Reset(bool shouldTriggerEvents = false) { throw new NotImplementedException(); } } }