public void Receive(GameEvent inEvent) { if (inEvent.EventID == (int)ETestRunenrEnum.Test1) { TestRunnerGameEvent1 event1 = inEvent as TestRunnerGameEvent1; testInt = event1.testInt; } }
public IEnumerator EventHandlerTestWithEnumeratorPasses() { GameEventHandler eventHandler = new GameEventHandler(); GameEventRouter eventRouter = new GameEventRouter(); EventHandlerSubscriber1 subscriber1 = new EventHandlerSubscriber1(); EventHandlerSubscriber2 subscriber2 = new EventHandlerSubscriber2(); EventHandlerSubscriber3 subscriber3 = new EventHandlerSubscriber3(); eventRouter.LinkPublisher(eventHandler); eventRouter.Subscribe((int)ETestRunenrEnum.Test1, subscriber1); eventRouter.Subscribe((int)ETestRunenrEnum.Test2, subscriber2); eventRouter.Subscribe((int)ETestRunenrEnum.Test1, subscriber3); eventRouter.Subscribe((int)ETestRunenrEnum.Test2, subscriber3); int testInt = 3; TestRunnerGameEvent1 event1 = new TestRunnerGameEvent1(); event1.testInt = testInt; float testFloat = 2.5f; TestRunnerGameEvent2 event2 = new TestRunnerGameEvent2(); event2.testFloat = testFloat; eventHandler.Publish(event1); eventHandler.Publish(event2); eventHandler.FireAllEvent(); Assert.AreEqual(testInt, subscriber1.testInt); Assert.AreEqual(testFloat, subscriber2.testFloat); Assert.AreEqual(testInt, subscriber3.testInt); Assert.AreEqual(testFloat, subscriber3.testFloat); eventRouter.UnSubscribe((int)ETestRunenrEnum.Test1, subscriber1); eventRouter.UnSubscribe((int)ETestRunenrEnum.Test2, subscriber3); int newTestInt = 999; float newTestFloat = 999.99f; event1.testInt = newTestInt; event2.testFloat = newTestFloat; eventHandler.Publish(event1); eventHandler.Publish(event2); eventHandler.FireAllEvent(); Assert.AreEqual(testInt, subscriber1.testInt); Assert.AreEqual(newTestFloat, subscriber2.testFloat); Assert.AreEqual(newTestInt, subscriber3.testInt); Assert.AreEqual(testFloat, subscriber3.testFloat); eventRouter.Clear(); System.GC.Collect(); newTestFloat = -123.45f; event2.testFloat = newTestFloat; eventHandler.Publish(event2); eventHandler.FireAllEvent(); Assert.AreNotEqual(newTestFloat, subscriber2.testFloat); yield return(null); }