2018-10-30 15:05:06 -04:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace UnityAtoms
|
|
|
|
{
|
2019-04-05 04:47:38 -04:00
|
|
|
public abstract class GameEvent<T> : ScriptableObject
|
2018-10-30 15:05:06 -04:00
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
private readonly List<IGameEventListener<T>> _eventListeners = new List<IGameEventListener<T>>();
|
2018-10-30 15:05:06 -04:00
|
|
|
|
|
|
|
public void Raise(T item)
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
for (int i = _eventListeners.Count - 1; i >= 0; i--)
|
|
|
|
_eventListeners[i].OnEventRaised(item);
|
2018-10-30 15:05:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void RegisterListener(IGameEventListener<T> listener)
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
if (!_eventListeners.Contains(listener))
|
|
|
|
_eventListeners.Add(listener);
|
2018-10-30 15:05:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void UnregisterListener(IGameEventListener<T> listener)
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
if (_eventListeners.Contains(listener))
|
|
|
|
_eventListeners.Remove(listener);
|
2018-10-30 15:05:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 04:47:38 -04:00
|
|
|
public abstract class GameEvent<T1, T2> : ScriptableObject
|
2018-10-30 15:05:06 -04:00
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
private readonly List<IGameEventListener<T1, T2>> _eventListeners = new List<IGameEventListener<T1, T2>>();
|
2018-10-30 15:05:06 -04:00
|
|
|
|
|
|
|
public void Raise(T1 item1, T2 item2)
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
for (int i = _eventListeners.Count - 1; i >= 0; i--)
|
|
|
|
_eventListeners[i].OnEventRaised(item1, item2);
|
2018-10-30 15:05:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void RegisterListener(IGameEventListener<T1, T2> listener)
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
if (!_eventListeners.Contains(listener))
|
|
|
|
_eventListeners.Add(listener);
|
2018-10-30 15:05:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void UnregisterListener(IGameEventListener<T1, T2> listener)
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
if (_eventListeners.Contains(listener))
|
|
|
|
_eventListeners.Remove(listener);
|
2018-10-30 15:05:06 -04:00
|
|
|
}
|
|
|
|
}
|
2019-03-17 18:43:20 -04:00
|
|
|
}
|