EventManager
Declaration
public static class Strawberry.EventSystem.EventManager
This is a static class that manages events in the game.
Methods
Subscribe static
Subscribe to an event globally.
SubscriptionToken Subscribe<T>(Action<T> callback, int priority = 0)
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
System.Action |
The callback to be called when the event is fired. |
priority |
System.Int32 = 0 |
The priority of the callback. Higher priority means it will be called first. Default is 0. |
Returns: A token used to unsubscribe from the event.
Type Parameters:
T— Event type
Subscribe static
Subscribes to an event for a specific instance of the object.
SubscriptionToken Subscribe<T>(object sender, Action<T> callback, int priority = 0)
Parameters:
| Name | Type | Description |
|---|---|---|
sender |
System.Object |
The object to subscribe to (source) |
callback |
System.Action |
The callback to invoke when the event is raised |
priority |
System.Int32 = 0 |
The priority of the callback. Higher priority means it will be called first. Default is 0. |
Returns: A token used to unsubscribe from the event.
Type Parameters:
T— Event type
Unsubscribe static
Unsubscribe from an event by token
void Unsubscribe(SubscriptionToken token)
Parameters:
| Name | Type | Description |
|---|---|---|
token |
Strawberry.EventSystem.SubscriptionToken |
The token returned from the Subscribe method |
Invoke static
Invokes an event. The method is not invoked instantly but rather queued for the next frame. The invoke time is determined by the EventCallTime property of the event object.
void Invoke<T>(object sender, T args)
Parameters:
| Name | Type | Description |
|---|---|---|
sender |
System.Object |
The object invoking the event |
args |
T |
The event object |
Type Parameters:
T— Event type
Execute static
This is called by Game class
void Execute(EventCallTime eventCallTime)
Parameters:
| Name | Type | Description |
|---|---|---|
eventCallTime |
Strawberry.EventSystem.EventCallTime |
The event group to execute |