using UnityEngine; using UnityEngine.Events; using UnityAtoms.Utils; namespace UnityAtoms { public class CreateVariableOnAwake : MonoBehaviour where V : ScriptableObjectVariable where E1 : GameEvent where E2 : GameEvent where L1 : GameEventListener where L2 : GameEventListener where GA1 : GameAction where GA2 : GameAction where GA3 : GameAction where GA4 : GameAction where UER1 : UnityEvent where UER2 : UnityEvent { [SerializeField] private bool CreateChangedEvent = true; [SerializeField] private bool CreateChangedWithHistoryEvent = false; [SerializeField] private L1 Listener = null; [SerializeField] private L2 ListenerWithHistory = null; [SerializeField] private GA3 OnVariableCreate = null; [SerializeField] private GA4 OnVariableCreateWithGO = null; void Awake() { var variable = DynamicAtoms.CreateVariable(CreateChangedEvent, CreateChangedWithHistoryEvent); if (variable.Changed != null) { if (Listener != null) { Listener.GameEvent = variable.Changed; Listener.GameEvent.RegisterListener(Listener); } } if (variable.ChangedWithHistory != null) { if (ListenerWithHistory != null) { ListenerWithHistory.GameEvent = variable.ChangedWithHistory; ListenerWithHistory.GameEvent.RegisterListener(ListenerWithHistory); } } if (OnVariableCreate != null) { OnVariableCreate.Do(variable); } if (OnVariableCreateWithGO != null) { OnVariableCreateWithGO.Do(variable, gameObject); } } } }