using UnityEngine; using UnityEngine.Events; using UnityAtoms.Utils; using UnityEngine.Serialization; namespace UnityAtoms { public abstract class CreateListOnAwake : MonoBehaviour where L : ScriptableObjectList where E : GameEvent where TEL : GameEventListener where TELR : GameAction where GA1 : GameAction where GA2 : GameAction where UER : UnityEvent { [FormerlySerializedAs("CreateAddedEvent")] [SerializeField] private bool _createAddedEvent = true; [FormerlySerializedAs("CreateRemovedEvent")] [SerializeField] private bool _createRemovedEvent = true; [FormerlySerializedAs("CreateClearedEvent")] [SerializeField] private bool _createClearedEvent = false; [FormerlySerializedAs("AddedListener")] [SerializeField] private TEL _addedListener = null; [FormerlySerializedAs("RemovedListener")] [SerializeField] private TEL _removedListener = null; [FormerlySerializedAs("ClearedListener")] [SerializeField] private VoidListener _clearedListener = null; [FormerlySerializedAs("OnListCreate")] [SerializeField] private GA1 _onListCreate = null; [FormerlySerializedAs("OnListCreateWithGO")] [SerializeField] private GA2 _onListCreateWithGO = null; private void Awake() { var list = DynamicAtoms.CreateList( added: _createAddedEvent ? ScriptableObject.CreateInstance() : null, removed: _createRemovedEvent ? ScriptableObject.CreateInstance() : null, cleared: _createClearedEvent ? ScriptableObject.CreateInstance() : null ); if (list.Added != null) { if (_addedListener != null) { _addedListener.GameEvent = list.Added; _addedListener.GameEvent.RegisterListener(_addedListener); } } if (list.Removed != null) { if (_removedListener != null) { _removedListener.GameEvent = list.Removed; _removedListener.GameEvent.RegisterListener(_removedListener); } } if (list.Cleared != null) { if (_clearedListener != null) { _clearedListener.GameEvent = list.Cleared; _clearedListener.GameEvent.RegisterListener(_clearedListener); } } if (_onListCreate != null) { _onListCreate.Do(list); } if (_onListCreateWithGO != null) { _onListCreateWithGO.Do(list, gameObject); } } } }