コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        private void RemoveListenerInternal(string name, EventAction action)
        {
            TSDevsUnityEvent unityEvent = null;

            if (Listeners.TryGetValue(name, out unityEvent))
            {
                unityEvent.RemoveListener(action);
            }
        }
コード例 #3
0
        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);
            }
        }