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 = 0; Action <EvSimpleEvent> callback = x => value += x.value; _system.Subscribe(target, callback); _system.QueueEvent(target, new EvSimpleEvent(10)); _system.ProcessEvents(); _system.Unsubscribe(target, callback); _system.VerifyNoSubscribers(); _system.QueueEvent(target, new EvSimpleEvent(10)); _system.ProcessEvents(); Assert.IsTrue(value == 10); }