2019-04-11 13:52:13 +02:00
|
|
|
using System;
|
2018-10-30 20:05:06 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace UnityAtoms
|
|
|
|
{
|
2019-04-05 10:47:38 +02:00
|
|
|
public abstract class GameEvent<T> : ScriptableObject
|
2018-10-30 20:05:06 +01:00
|
|
|
{
|
2019-04-11 13:52:13 +02:00
|
|
|
public event Action<T> OnEvent;
|
2018-10-30 20:05:06 +01:00
|
|
|
|
|
|
|
public void Raise(T item)
|
|
|
|
{
|
2019-04-11 13:52:13 +02:00
|
|
|
OnEvent?.Invoke(item);
|
2018-10-30 20:05:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void RegisterListener(IGameEventListener<T> listener)
|
|
|
|
{
|
2019-04-11 13:52:13 +02:00
|
|
|
OnEvent += listener.OnEventRaised;
|
2018-10-30 20:05:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void UnregisterListener(IGameEventListener<T> listener)
|
|
|
|
{
|
2019-04-11 13:52:13 +02:00
|
|
|
OnEvent -= listener.OnEventRaised;
|
2018-10-30 20:05:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 10:47:38 +02:00
|
|
|
public abstract class GameEvent<T1, T2> : ScriptableObject
|
2018-10-30 20:05:06 +01:00
|
|
|
{
|
2019-04-11 13:52:13 +02:00
|
|
|
public event Action<T1, T2> OnEvent;
|
2018-10-30 20:05:06 +01:00
|
|
|
|
|
|
|
public void Raise(T1 item1, T2 item2)
|
|
|
|
{
|
2019-04-11 13:52:13 +02:00
|
|
|
OnEvent?.Invoke(item1, item2);
|
2018-10-30 20:05:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void RegisterListener(IGameEventListener<T1, T2> listener)
|
|
|
|
{
|
2019-04-11 13:52:13 +02:00
|
|
|
OnEvent += listener.OnEventRaised;
|
2018-10-30 20:05:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void UnregisterListener(IGameEventListener<T1, T2> listener)
|
|
|
|
{
|
2019-04-11 13:52:13 +02:00
|
|
|
OnEvent -= listener.OnEventRaised;
|
2018-10-30 20:05:06 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-17 23:43:20 +01:00
|
|
|
}
|