Custom Events
While this library provides many of the common Unity types you will use, you may want to extend this library with your own custom events specific to your application. Fortunately, this is rather easy and typically only involves creating a derived class from one of the base classes. You may also add any additional helper properties and methods as you need.
Channels
- Create a new class that derives from
EventChannel<T>
, whereT
should be the type of event data. - Ensure the new type is marked with the
CreateAssetMenu
attribute, so you can create instances in the Editor. - Create any instances of the new event channel in your
Assets
folder. - Now you can use them throughout your application.
NOTE: If you want a custom VoidEventChannel
, derive from that class instead of the EventChannel
base class.
This will ensure you also get the custom editor for manually invoking the event.
Listeners
- Create a new class that derives from
EventListener<T, TChannel>
whereT
should be the underlying type andTChannel
is the event channel type. - Now you can use the event listener in your components
NOTE: If you want a custom VoidEventListener
, derive from that class instead of the EventListener<TChannel>
base class.
This will ensure you also get the custom editor for manually invoking the event.