示例#1
0
 private void GetOutFromEventManagerDispatcher()
 {
     if (EventManagerDispatcher <TEvent> .GetEventManagerHardInternal() == this)
     {
         EventManagerDispatcher <TEvent> .RemoveEventManagerInternal();
     }
 }
示例#2
0
        public void EventManagerShouldCreateDefaultInstanceForEventTypeTest()
        {
            ClearEventManager();
            var eventManager = EventManagerDispatcher <EventManagerTestsEvent> .GetEventManager();

            Assert.NotNull(eventManager);
        }
示例#3
0
        public void EventManagerShouldAddHandleTest()
        {
            var eventManager = EventManagerDispatcher <EventManagerTestsEvent> .GetEventManager();

            var handler = new CustomActionHandler <EventManagerTestsEvent>();

            eventManager.AddHandler(handler);
            Assert.Contains(handler, eventManager.GetEventHandlers().ToArray());
        }
示例#4
0
        public static void RemoveHandler <TEvent>(Action <TEvent> handler)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                throw new PlatformNotSupportedException();
            }
#endif
            var actionHandlerAdapter = ActionHandlerAdapterBuilder.Create(handler);
            EventManagerDispatcher <TEvent> .GetEventManager().RemoveHandler(actionHandlerAdapter);
        }
示例#5
0
        public static void RemoveHandler <TEvent>(IEventHandler <TEvent> handler)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                throw new PlatformNotSupportedException();
            }
#endif
            if (handler is Object target)
            {
                handler = UnityHandlerAdapterBuilder.Create(handler, target);
            }

            EventManagerDispatcher <TEvent> .GetEventManager().RemoveHandler(handler);
        }
示例#6
0
        public static Routine EventAsync <TEvent>(TEvent arg)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                throw new PlatformNotSupportedException();
            }
#endif

            var handlers = EventManagerDispatcher <TEvent> .GetEventManager().GetEventHandlers();

            var runner = EventHandlerRunnerBuilder <TEvent> .Create(handlers, arg);

            return(EventScheduler.ExecuteAsync(runner));
        }
示例#7
0
        public static void Event <TEvent>(TEvent arg)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                throw new PlatformNotSupportedException();
            }
#endif

            var handlers = EventManagerDispatcher <TEvent> .GetEventManager().GetEventHandlers();

            var runner = EventHandlerRunnerBuilder <TEvent> .Create(handlers, arg);

            EventScheduler.Schedule(runner);
        }
示例#8
0
        public void ShouldLogExceptionAndResetQueueEventsWhenHandlerThrowExceptionTest()
        {
            string keyMessage = nameof(keyMessage);

            EventAggregator.AddHandler <NotIsolateEvent>(_ => EventAggregator.Event <IsolateEvent>(new IsolateEvent()));
            EventAggregator.AddHandler <IsolateEvent>(_ => Assert.Fail());

            EventAggregator.AddHandler <NotIsolateEvent>(_ => throw new Exception(keyMessage));
            EventAggregator.AddHandler <NotIsolateEvent>(_ => Assert.Fail());

            LogAssert.Expect(LogType.Exception, new Regex(".keyMessage"));
            EventAggregator.Event(new NotIsolateEvent());

            EventManagerDispatcher <NotIsolateEvent> .RemoveEventManagerInternal();

            EventManagerDispatcher <IsolateEvent> .RemoveEventManagerInternal();
        }
示例#9
0
        public void ShouldLogExceptionAndShouldNotResetQueueEventsAndNotStopCurrentEventWhenHandlerThrowExceptionTest()
        {
            string keyMessage = nameof(keyMessage);
            bool   flagFromIsolateHandlers = false;
            bool   flagFromIsolateEvent    = false;

            EventAggregator.AddHandler <IsolateHandlersEvent>(_ => throw new Exception(keyMessage));
            EventAggregator.AddHandler <IsolateHandlersEvent>(_ => flagFromIsolateHandlers = true);
            EventAggregator.AddHandler <IsolateHandlersEvent>(_ => EventAggregator.Event(new IsolateEvent()));
            EventAggregator.AddHandler <IsolateEvent>(_ => flagFromIsolateEvent = true);

            LogAssert.Expect(LogType.Exception, new Regex(".keyMessage"));
            EventAggregator.Event(new IsolateHandlersEvent());

            Assert.True(flagFromIsolateHandlers);
            Assert.True(flagFromIsolateEvent);

            EventManagerDispatcher <IsolateHandlersEvent> .RemoveEventManagerInternal();

            EventManagerDispatcher <IsolateEvent> .RemoveEventManagerInternal();
        }
 public void ClearHandlers()
 => EventManagerDispatcher <TestEvent> .RemoveEventManagerInternal();