using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; namespace UnityAtoms { public abstract class GameEventListener : MonoBehaviour, IGameEventListener where GA : GameAction where E : GameEvent where UER : UnityEvent { [SerializeField] private E Event = null; public E GameEvent { get { return Event; } set { Event = value; } } [SerializeField] private UER UnityEventResponse = null; [SerializeField] private List GameActionResponses = new List(); private void OnEnable() { if (Event == null) return; GameEvent.RegisterListener(this); } private void OnDisable() { GameEvent.UnregisterListener(this); } public void OnEventRaised(T item) { if (UnityEventResponse != null) { UnityEventResponse.Invoke(item); } for (int i = 0; GameActionResponses != null && i < GameActionResponses.Count; ++i) { GameActionResponses[i].Do(item); } } } public abstract class GameEventListener : MonoBehaviour, IGameEventListener where GA : GameAction where E : GameEvent where UER : UnityEvent { [SerializeField] private E Event = null; public E GameEvent { get { return Event; } set { Event = value; } } [SerializeField] private UER UnityEventResponse = null; [SerializeField] private List GameActionResponses = new List(); private void OnEnable() { if (Event == null) return; GameEvent.RegisterListener(this); } private void OnDisable() { if (Event == null) return; GameEvent.UnregisterListener(this); } public void OnEventRaised(T1 first, T2 second) { if (UnityEventResponse != null) { UnityEventResponse.Invoke(first, second); } for (int i = 0; GameActionResponses != null && i < GameActionResponses.Count; ++i) { GameActionResponses[i].Do(first, second); } } } }