private void GetOutFromEventManagerDispatcher() { if (EventManagerDispatcher <TEvent> .GetEventManagerHardInternal() == this) { EventManagerDispatcher <TEvent> .RemoveEventManagerInternal(); } }
public void EventManagerShouldCreateDefaultInstanceForEventTypeTest() { ClearEventManager(); var eventManager = EventManagerDispatcher <EventManagerTestsEvent> .GetEventManager(); Assert.NotNull(eventManager); }
public void EventManagerShouldAddHandleTest() { var eventManager = EventManagerDispatcher <EventManagerTestsEvent> .GetEventManager(); var handler = new CustomActionHandler <EventManagerTestsEvent>(); eventManager.AddHandler(handler); Assert.Contains(handler, eventManager.GetEventHandlers().ToArray()); }
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); }
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); }
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)); }
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); }
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(); }
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();