using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; namespace UnityAtoms { public class CreateEventOnAwake : MonoBehaviour where E1 : GameEvent where E2 : GameEvent where L1 : GameEventListener where L2 : GameEventListener where GA1 : GameAction where GA2 : GameAction where UER1 : UnityEvent where UER2 : UnityEvent where MH : MonoHook { public bool CreateEvent = true; public bool CreateEventWithGameObject = false; public List MonoHooks; public L1 Listener; public L2 ListenerWithGameObject; void Awake() { var e1 = CreateEvent ? ScriptableObject.CreateInstance() : null; var e2 = CreateEventWithGameObject ? ScriptableObject.CreateInstance() : null; if (e1 != null) { for (int i = 0; MonoHooks != null && i < MonoHooks.Count; ++i) { MonoHooks[i].Event = e1; } if (Listener != null) { Listener.GameEvent = e1; e1.RegisterListener(Listener); } } if (e2 != null) { for (int i = 0; MonoHooks != null && i < MonoHooks.Count; ++i) { MonoHooks[i].EventWithGORef = e2; } if (ListenerWithGameObject != null) { ListenerWithGameObject.GameEvent = e2; e2.RegisterListener(ListenerWithGameObject); } } } } }