Advertisement
Pro_Unit

EventListener

Dec 22nd, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2.  
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5.  
  6. [Serializable]
  7. public class EventListener
  8. {
  9.     [SerializeField] GameEvent Event;
  10.  
  11.     [SerializeField] UnityEvent Responce;
  12.     public EventListener (GameEvent startEvent, UnityAction action)
  13.     {
  14.         Event = startEvent;
  15.         Responce = new UnityEvent ();
  16.         Responce.AddListener (action);
  17.     }
  18.  
  19.     public void OnEventRaised ()
  20.     {
  21.         Responce.Invoke ();
  22.     }
  23.     public bool OnEnable ()
  24.     {
  25.         bool IfNotNullEvent = Event != null;
  26.         if (IfNotNullEvent)
  27.             Event.RegisterListener (this);
  28.         return IfNotNullEvent;
  29.     }
  30.  
  31.     public bool OnDisable ()
  32.     {
  33.         bool IfNotNullEvent = Event != null;
  34.         if (IfNotNullEvent)
  35.             Event.UnRegisterListener (this);
  36.         return IfNotNullEvent;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement