A lightweight publisher-subscriber framework used by Studio Root Games. Can be copied directly into a project, turned into a Unity Package Manager package, or added to a project initialized as an npm package using npm install jordanstudioroot/RootEvents-UnityCSharp
.
- Declare an event by instantiating a new RootEvent:
RootEvent<Argument, Response> foo = new RootEvent<Argument, Response>();
- Subscribe a function of the corresponding signature to the event by passing it as an argument to the event:
foo.Subscribe(HandlerFunction);
- Fire the event as needed, passing the object publishing the event and any required arguments to the event:
foo.Publish(this, argument);
- When the event is no longer relevant to a particular object, or in general, call
foo.Unsubscribe(HandlerFunction);
orfoo.UnsubscribeAll();
Declare the events in a central event aggregator if you have numerous events and numerous subscribers.
- Tests
- Example event aggregator class.