Run one scene to compare untargeted, targeted, and broadcast messages in a small combat flow.
- Open Window > Package Manager.
- Select DxMessaging, then import Mini Combat.
- Open
MiniCombat.unityfrom the imported sample folder. - Enter Play Mode. Watch the combat feed in the Game view and the gameplay output in the Console.
The scene is already wired. Boot emits three messages after every listener has registered:
VideoSettingsChangedis untargeted, soUIOverlayobserves a global settings change.Healtargets onePlayercomponent, so another player would not receive it.TookDamagebroadcasts from theEnemyGameObject, so observers retain source context.
| File | Responsibility |
|---|---|
| Messages.cs | Declares the three message contracts. |
| Player.cs | Applies a targeted heal to one player. |
| Enemy.cs | Broadcasts damage with its GameObject as the source. |
| UIOverlay.cs | Presents global settings and damage from any source in the Game view. |
| Boot.cs | Starts the deterministic flow and owns any fallback objects it creates. |
| Walkthrough.md | Explains route choice, lifecycle, and extension points. |
MessageAwareComponent creates and owns a registration token. Register handlers in
RegisterMessageHandlers and call the base implementation first:
protected override void RegisterMessageHandlers()
{
base.RegisterMessageHandlers();
_ = Token.RegisterComponentTargeted<Heal>(this, OnHeal);
}Emit struct messages from variables because the generated extension methods take the message by reference:
var heal = new Heal(10);
heal.EmitComponentTargeted(player);The included scene serializes every reference. If you place Boot in an empty scene,
it creates the missing Player, Enemy, and UIOverlay components before Start.
Boot records exactly which GameObjects it created and destroys only those objects in
OnDestroy; it never destroys scene-owned or user-assigned objects.
- Add another
Playerand target it explicitly to verify component isolation. - Add an audio listener for
TookDamagewithout changingEnemy. - Add an analytics post-processor when you need a measurement after gameplay handlers have completed. Keep gameplay state changes in handlers.
If you override Awake, OnEnable, OnDisable, OnDestroy, or
RegisterMessageHandlers in a MessageAwareComponent subclass, call the corresponding
base method first. The package analyzers report missing base calls.