slimecing

a fighting game featuring slimes and swords
Log | Files | Refs | README

BaseGameEventListener.cs (921B)


      1 using Slimecing.Events;
      2 using Slimecing.SOEventSystem.Events;
      3 using UnityEngine;
      4 using UnityEngine.Events;
      5 
      6 namespace Slimecing.SOEventSystem.Listeners
      7 {
      8     public abstract class BaseGameEventListener<T, E, UER> : MonoBehaviour,
      9         IGameEventListener<T> where E : BaseGameEvent<T> where UER : UnityEvent<T>
     10     {
     11         [SerializeField] private E gameEvent;
     12         public E GameEvent { get { return gameEvent; } set {gameEvent = value;} }
     13 
     14         [SerializeField] private UER unityEventResponse;
     15 
     16         private void OnEnable()
     17         {
     18             if(gameEvent == null) { return; }
     19 
     20             GameEvent.RegisterListener(this);
     21         }
     22 
     23         private void OnDisable()
     24         {
     25             if(gameEvent == null) { return; }
     26 
     27             GameEvent.UnregisterListener(this);
     28         }
     29 
     30         public void OnEventRaised(T thing)
     31         {
     32             unityEventResponse?.Invoke(thing);
     33         }
     34     }
     35 }