Table of Contents

Class Mediator

A concrete, event-bus style Mediator implementation. Components subscribe to named event channels and are notified whenever another component calls Notify(object, string, object).

public class Mediator : IMediator
Inheritance
Mediator
Implements
Inherited Members

Examples

var mediator = new Mediator();
mediator.Subscribe("OnScoreChanged", (sender, data) => Debug.Log($"Score: {data}"));
mediator.Notify(this, "OnScoreChanged", 42);

Remarks

Useful for cross-system communication (e.g. UI reacting to game-world events) without creating direct dependencies between the systems.

Methods

Notify(object, string, object)

Broadcasts an event to all subscribers registered under eventKey.

public void Notify(object sender, string eventKey, object data = null)

Parameters

sender object

The object raising the event.

eventKey string

A string identifier for the event channel (e.g. "OnPlayerDied").

data object

Optional payload accompanying the event.

Subscribe(string, Action<object, object>)

Subscribes callback to the named event channel.

public void Subscribe(string eventKey, Action<object, object> callback)

Parameters

eventKey string

The event channel identifier.

callback Action<object, object>

Callback invoked with (sender, data) when the event fires.

Unsubscribe(string, Action<object, object>)

Removes callback from the named event channel.

public void Unsubscribe(string eventKey, Action<object, object> callback)

Parameters

eventKey string

The event channel identifier.

callback Action<object, object>

The callback to remove.