Astra Unity 2.6.6
Astra Unity Plugin
Astra.Utils.EventBus Class Reference

An event routing system following the Publisher/Subscriber paradigm Implements the Events class More...

Inheritance diagram for Astra.Utils.EventBus:

Classes

interface  ISubscription
 Interface for the Subscription class More...
 
class  Subscription
 A class representing the association between event, subscriber, and subscriber callback method to invoke on event publication Implements the ISubscription interface More...
 

Public Member Functions

 EventBus ()
 EventBus constructor Initialize the subscriptions dictionary
 

Static Public Member Functions

static void Publish< TBusEvent > (TBusEvent busEvent)
 Notifies and invokes callbacks on all subscribers listening for given event More...
 
static void Subscribe< TBusEvent, TSubscriber > (Action< TBusEvent > callback, TSubscriber subscriber)
 Registers subscriber for notification when the specified event is published More...
 
static void Unsubscribe< TBusEvent, TSubscriber > (TSubscriber subscriber)
 Remove subscription representing association between subscriber and the given event type Note: To avoid memory issues, make sure that objects unsubscribe before they are destroyed, sleep, etc. More...
 
static void ClearSubscriptions ()
 Clears all the subscriptions that are attached to the EventBus.
 

Properties

static EventBus Instance [get]
 A static instance of EventBus which maintains event / subscriber + callback associations only indirectly accessible through the Publish/Subscribe/Unsubscribe methods
 

Detailed Description

An event routing system following the Publisher/Subscriber paradigm Implements the Events class

Member Function Documentation

◆ Publish< TBusEvent >()

static void Astra.Utils.EventBus.Publish< TBusEvent > ( TBusEvent  busEvent)
inlinestatic

Notifies and invokes callbacks on all subscribers listening for given event

Template Parameters
TBusEventType of event to publish
Parameters
busEventInstance of the event item to publish
Type Constraints
TBusEvent :BusEvent 

◆ Subscribe< TBusEvent, TSubscriber >()

static void Astra.Utils.EventBus.Subscribe< TBusEvent, TSubscriber > ( Action< TBusEvent >  callback,
TSubscriber  subscriber 
)
inlinestatic

Registers subscriber for notification when the specified event is published

Template Parameters
TBusEventType of event to publish
TSubscriberType of subscriber
Parameters
callbackCallback to be invoked on publication of given event
subscriberA reference to the subscribing Object
Type Constraints
TBusEvent :BusEvent 
TSubscriber :UnityEngine.Object 

◆ Unsubscribe< TBusEvent, TSubscriber >()

static void Astra.Utils.EventBus.Unsubscribe< TBusEvent, TSubscriber > ( TSubscriber  subscriber)
inlinestatic

Remove subscription representing association between subscriber and the given event type Note: To avoid memory issues, make sure that objects unsubscribe before they are destroyed, sleep, etc.

Template Parameters
TBusEventType of event to which to unsubscribe
TSubscriberType of subscriber
Parameters
subscriberA reference to the subscribed Object
Type Constraints
TBusEvent :BusEvent 
TSubscriber :UnityEngine.Object 

The documentation for this class was generated from the following file: