private void TriggerEventInternal(IEvent triggeredEvent) { if (LoggingEnabled) { Log.Debug($"[EventService] Triggered event for {triggeredEvent.Name} with lifespan of {triggeredEvent.Lifespan}"); } if (triggeredEvent.Lifespan != EventLifespan.Instant) { if (Events.ContainsKey(triggeredEvent.Name)) { Events[triggeredEvent.Name].Add(triggeredEvent); } else { Events.Add(triggeredEvent.Name, new EventsList() { triggeredEvent }); } } TSDevsUnityEvent unityEvent = null; if (Listeners.TryGetValue(triggeredEvent.Name, out unityEvent)) { if (!triggeredEvent.IsHandled) { unityEvent.Invoke(triggeredEvent); } } }
private void RemoveListenerInternal(string name, EventAction action) { TSDevsUnityEvent unityEvent = null; if (Listeners.TryGetValue(name, out unityEvent)) { unityEvent.RemoveListener(action); } }
private void AddListenerInternal(string name, EventAction action) { TSDevsUnityEvent unityEvent = null; if (Listeners.TryGetValue(name, out unityEvent)) { unityEvent.AddListener(action); } else { unityEvent = new TSDevsUnityEvent(); unityEvent.AddListener(action); Listeners.Add(name, unityEvent); } }