using System; using System.Collections.Generic; using TapSDK.UI; namespace TapSDK.Core.Internal.Utils { public sealed class EventManager : Singleton { public const string OnApplicationPause = "OnApplicationPause"; public const string OnApplicationQuit = "OnApplicationQuit"; public const string OnComplianceUserChanged = "OnComplianceUserChanged"; public const string OnTapUserChanged = "OnTapUserChanged"; public const string IsLaunchedFromTapTapPCFinished = "IsLaunchedFromTapTapPCFinished"; private Dictionary> eventRegistries = new Dictionary>(); public static void AddListener(string eventName, Action listener) { if (listener == null) return; if (string.IsNullOrEmpty(eventName)) return; Action thisEvent; if (Instance.eventRegistries.TryGetValue(eventName, out thisEvent)) { thisEvent += listener; Instance.eventRegistries[eventName] = thisEvent; } else { thisEvent += listener; Instance.eventRegistries.Add(eventName, thisEvent); } } public static void RemoveListener(string eventName, Action listener) { if (listener == null) return; if (string.IsNullOrEmpty(eventName)) return; Action thisEvent; if (Instance.eventRegistries.TryGetValue(eventName, out thisEvent)) { thisEvent -= listener; Instance.eventRegistries[eventName] = thisEvent; } } public static void TriggerEvent(string eventName, object message) { Action thisEvent = null; if (Instance.eventRegistries.TryGetValue(eventName, out thisEvent)) { thisEvent.Invoke(message); } } } }