EventBus Class
Singleton event bus for publish/subscribe messaging between systems and components. Thread-safe: Subscribe, Unsubscribe, and ClearAll may be called from any thread. Publish is allocation-free on the hot path; it reads a pre-committed handler array without holding the lock during invocation.
internal sealed class EventBus : Brine2D.Events.IEventBus
Inheritance System.Object → EventBus
Implements IEventBus
| Methods | |
|---|---|
| ClearAll() | Clears all subscribers for all event types. |
| ClearSubscribers<T>() | Clears all subscribers for a specific event type. |
| Publish<T>(T) | Publishes an event to all current subscribers of type T. Exceptions thrown by individual handlers are caught and logged; remaining handlers still execute. Allocation-free on the hot path. |
| Subscribe<T>(Action<T>) | Subscribes to events of type T and returns a disposal token that unsubscribes automatically when disposed. Prefer this overload to avoid stale subscriptions when scenes are unloaded: `...` |
| Unsubscribe<T>(Action<T>) | Manually unsubscribes a handler. Prefer disposing the token returned by Subscribe<T>(Action<T>) — it calls this method and is idempotent. |