using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; 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; [SerializeField] private L2 ListenerWithHistory; [SerializeField] private GA3 OnVariableCreate; [SerializeField] private GA4 OnVariableCreateWithGO; void Awake() { var variable = VariableUtils.RuntimeCreate(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); } } } }