unity-atoms/Source/Base/GameEvent.cs
Jeff Campbell e5f6659eda Removed unused namepaces
* Removed unused namespaces across all files in Unity.Atoms assembly.
* Removed unused namspaces in runtime and Test assembly code.
2019-04-07 11:15:23 +02:00

52 lines
1.5 KiB
C#

using System.Collections.Generic;
using UnityEngine;
namespace UnityAtoms
{
public abstract class GameEvent<T> : ScriptableObject
{
private readonly List<IGameEventListener<T>> eventListeners = new List<IGameEventListener<T>>();
public void Raise(T item)
{
for (int i = eventListeners.Count - 1; i >= 0; i--)
eventListeners[i].OnEventRaised(item);
}
public void RegisterListener(IGameEventListener<T> listener)
{
if (!eventListeners.Contains(listener))
eventListeners.Add(listener);
}
public void UnregisterListener(IGameEventListener<T> listener)
{
if (eventListeners.Contains(listener))
eventListeners.Remove(listener);
}
}
public abstract class GameEvent<T1, T2> : ScriptableObject
{
private readonly List<IGameEventListener<T1, T2>> eventListeners = new List<IGameEventListener<T1, T2>>();
public void Raise(T1 item1, T2 item2)
{
for (int i = eventListeners.Count - 1; i >= 0; i--)
eventListeners[i].OnEventRaised(item1, item2);
}
public void RegisterListener(IGameEventListener<T1, T2> listener)
{
if (!eventListeners.Contains(listener))
eventListeners.Add(listener);
}
public void UnregisterListener(IGameEventListener<T1, T2> listener)
{
if (eventListeners.Contains(listener))
eventListeners.Remove(listener);
}
}
}