using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; namespace MeadowGames.UINodeConnect4 { public enum UICEventType { OnPointerDown, OnDrag, OnPointerUp, OnDeleteKeyPressed, OnPointerHoverEnter, OnPointerHoverExit, OnConnectionCreated, OnConnectionRemoved, NodeAdded, NodeRemoved, ConnectionAdded, ConnectionRemoved, OnElementSelected, OnElementUnselected } [System.Serializable] public class UICEvent : UnityEvent { } public class EventManager { Dictionary> _eventDictionaryElement; public EventManager() { if (_eventDictionaryElement == null) { _eventDictionaryElement = new Dictionary>(); } } public void StartListening(UICEventType eventName, UnityAction listener) { UICEvent thisEvent = null; if (_eventDictionaryElement.TryGetValue(eventName, out thisEvent)) { thisEvent.AddListener(listener); } else { thisEvent = new UICEvent(); thisEvent.AddListener(listener); _eventDictionaryElement.Add(eventName, thisEvent); } } public void StopListening(UICEventType eventName, UnityAction listener) { UICEvent thisEvent = null; if (_eventDictionaryElement.TryGetValue(eventName, out thisEvent)) { thisEvent.RemoveListener(listener); } } public void TriggerEvent(UICEventType eventName, T obj) { UICEvent thisEvent = null; if (_eventDictionaryElement.TryGetValue(eventName, out thisEvent)) { thisEvent.Invoke(obj); } } } }