HKI Core
GameEvent.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using System.Collections.Generic;
3 
4 namespace HKI.Core.GameEvents
5 {
11  [CreateAssetMenu(fileName = "GameEvent", menuName = "HKI/Game Event", order = 0)]
12  public class GameEvent : ScriptableObject
13  {
14  // Variables
18  List<GameEventListener> listeners = new List<GameEventListener>();
19 
20  // Interface function
24  public void Raise()
25  {
26  for(int i = listeners.Count - 1; i >= 0; i--)
27  {
28  if (listeners[i] != null)
29  listeners[i].OnEventRaised();
30  }
31  }
32 
37  public void RegisterListener(GameEventListener listener)
38  {
39  if (listener != null && !listeners.Contains(listener))
40  listeners.Add(listener);
41  }
42 
47  public void UnregisterListener(GameEventListener listener)
48  {
49  listeners.Remove(listener);
50  }
51  }
52 }
void Raise()
Calling this function will inform all registered listener that this event is raised.
Definition: GameEvent.cs:24
void RegisterListener(GameEventListener listener)
Register a listerner to this event. The listener will be informed that this event is raised...
Definition: GameEvent.cs:37
This is the listener class for GameEvents. This class binds the Event with the callbacks (here called...
This is a ScriptableObject game event. It can be listen too and raised via code or within Unity Edito...
Definition: GameEvent.cs:12
void UnregisterListener(GameEventListener listener)
Remove a listerner from this event. From now on the listener won&#39;t be informed that this event is rai...
Definition: GameEvent.cs:47