Skip to content

Instantly share code, notes, and snippets.

@wowbroforce
Created February 15, 2020 19:00
Show Gist options
  • Save wowbroforce/0c5e57d2af6a59d7d3ffd85849365f13 to your computer and use it in GitHub Desktop.
Save wowbroforce/0c5e57d2af6a59d7d3ffd85849365f13 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections.Generic;
[CreateAssetMenu(fileName = "GameEvent", menuName = "~/Assets/Scripts/GameEvent", order = 0)]
public class GameEvent : ScriptableObject
{
private List<GameEventListener> listeners = new List<GameEventListener>();
public void Raise()
{
for (var i = listeners.Count - 1; i >= 0; i--)
listeners[i].OnEventRised();
}
public void Register(GameEventListener listener)
{
listeners.Add(listener);
}
public void Unregister(GameEventListener listener)
{
listeners.Remove(listener);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment