BaseGameEvent.cs (985B)
1 using System.Collections.Generic; 2 using Slimecing.Events; 3 using Slimecing.SOEventSystem.Listeners; 4 using UnityEngine; 5 6 namespace Slimecing.SOEventSystem.Events 7 { 8 public abstract class BaseGameEvent<T> : ScriptableObject 9 { 10 private readonly List<IGameEventListener<T>> eventListeners = new List<IGameEventListener<T>>(); 11 12 public void Raise(T thing) 13 { 14 for (int i = eventListeners.Count - 1; i >= 0; i--) 15 { 16 eventListeners[i].OnEventRaised(thing); 17 } 18 } 19 20 public void RegisterListener(IGameEventListener<T> listener) 21 { 22 if (!eventListeners.Contains(listener)) 23 { 24 eventListeners.Add(listener); 25 } 26 } 27 public void UnregisterListener(IGameEventListener<T> listener) 28 { 29 if (eventListeners.Contains(listener)) 30 { 31 eventListeners.Remove(listener); 32 } 33 34 } 35 } 36 }