-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameEvent.cs
40 lines (35 loc) · 1.02 KB
/
GameEvent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
namespace Bewildered.Events
{
[CreateAssetMenu(order = 100)]
public class GameEvent : ScriptableObject
{
private List<GameEventListener> _listeners = new List<GameEventListener>();
#if UNITY_EDITOR
private List<StackTrace> _stackTraces = new List<StackTrace>();
#endif
/// <summary>
/// Raises the event. Invoking the Response from all registered GameEventListeners.
/// </summary>
public void Raise()
{
#if UNITY_EDITOR
_stackTraces.Add(new StackTrace(true));
#endif
for (int i = _listeners.Count - 1; i >= 0; i--)
{
_listeners[0].OnEventRaised();
}
}
internal void RegisterListener(GameEventListener listener)
{
_listeners.Add(listener);
}
internal void UnregisterListener(GameEventListener listener)
{
_listeners.Remove(listener);
}
}
}