using System; using System.Collections.Generic; using UnityEngine; namespace UnityAtoms { [Serializable] public abstract class GameEvent : ScriptableObject, IGameEvent { private readonly List> eventListeners = new List>(); public void Raise(T item) { for (int i = eventListeners.Count - 1; i >= 0; i--) eventListeners[i].OnEventRaised(item); } public void RegisterListener(IGameEventListener listener) { if (!eventListeners.Contains(listener)) eventListeners.Add(listener); } public void UnregisterListener(IGameEventListener listener) { if (eventListeners.Contains(listener)) eventListeners.Remove(listener); } } [Serializable] public abstract class GameEvent : ScriptableObject, IGameEvent { private readonly List> eventListeners = new List>(); public void Raise(T1 item1, T2 item2) { for (int i = eventListeners.Count - 1; i >= 0; i--) eventListeners[i].OnEventRaised(item1, item2); } public void RegisterListener(IGameEventListener listener) { if (!eventListeners.Contains(listener)) eventListeners.Add(listener); } public void UnregisterListener(IGameEventListener listener) { if (eventListeners.Contains(listener)) eventListeners.Remove(listener); } } }