using UnityEngine; namespace UnityAtoms { public abstract class ScriptableObjectVariable : ScriptableObjectVariableBase, IWithOldValue where E1 : GameEvent where E2 : GameEvent { public override T Value { get { return value; } set { SetValue(value); } } public T OldValue { get { return oldValue; } } [SerializeField] private T oldValue; public E1 Changed; public E2 ChangedWithHistory; protected abstract bool AreEqual(T first, T second); private void OnEnable() { if (Changed == null) return; Changed.Raise(Value); } public bool SetValue(T value) { if (!AreEqual(this.value, value)) { this.oldValue = this.value; this.value = value; if (Changed != null) { Changed.Raise(value); } if (ChangedWithHistory != null) { ChangedWithHistory.Raise(this.value, this.oldValue); } return true; } return false; } public bool SetValue(ScriptableObjectVariable variable) { return SetValue(variable.Value); } } }