Advertisement
Pro_Unit

GameEventGameObject

Nov 16th, 2020
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1.  
  2. using System.Collections.Generic;
  3.  
  4. using UnityEngine;
  5. namespace GameCore
  6. {
  7.     [CreateAssetMenu(fileName = "GameEventGameObject", menuName = "GameCore/GameEvent/GameObject")]
  8.     public class GameEventGameObject : ScriptableObject
  9.     {
  10.         [SerializeField]
  11.         public List<GameEventListenerGameObject> eventListeners = new List<GameEventListenerGameObject>();
  12.  
  13.         public void Raise(GameObject arg)
  14.         {
  15.             for (int i = eventListeners.Count - 1; i >= 0; i--)
  16.                 if (i < eventListeners.Count)
  17.                     eventListeners[i].OnEventRaised(arg);
  18.         }
  19.  
  20.         public virtual void RegisterListener(GameEventListenerGameObject listener)
  21.         {
  22.             if (!eventListeners.Contains(listener))
  23.                 eventListeners.Add(listener);
  24.         }
  25.  
  26.         public virtual void UnRegisterListener(GameEventListenerGameObject listener)
  27.         {
  28.             if (eventListeners.Contains(listener))
  29.                 eventListeners.Remove(listener);
  30.         }
  31.     }
  32.  
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement