public void StandardHandlerExample() { // Handlers ultimately are what store the subscriptions and process events. Ideally they shouldn't need // to be used directly and TickEventSystem and UnityEventSystem would be sufficient in most cases. // See ExampleControlledEventSystem.cs for a description on EventEntities. EventTarget target = EventTarget.CreateTarget(); // Subscribe, Unsubscribe, and Events will seem familiar but can ONLY use EvExampleEvent. Doesn't work for // all events. _standardHandler.Subscribe(target, OnExampleEvent); // Handlers have to be told to process events so we queue an event and process it later. _standardHandler.QueueEvent(target, new EvExampleEvent(7777)); _standardHandler.ProcessEvents(); _standardHandler.Unsubscribe(target, OnExampleEvent); // There's a job handler as well, they are separate and won't fire on the same events _jobHandler.Subscribe(target, new ExampleJob(), OnJobFinished); _jobHandler.QueueEvent(target, new EvExampleEvent(111)); _jobHandler.ProcessEvents(); _jobHandler.Unsubscribe(target, OnJobFinished); }
public void TestSimpleEvent() { EventTarget target = EventTarget.CreateTarget(); int value = 10; Action <TestJob> callback = x => { Assert.IsTrue(x.result == value); }; _handler.Subscribe(target, new TestJob(value), callback); _handler.QueueEvent(target, new EvSimpleEvent(10)); value = 20; _handler.ProcessEvents(); _handler.Unsubscribe(target, callback); _handler.VerifyNoSubscribers(); _handler.QueueEvent(target, new EvSimpleEvent(10)); _handler.ProcessEvents(); }