com.wallstop-studios.dxmessaging 2.2.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/CHANGELOG.md +315 -67
  2. package/CHANGELOG.md.meta +7 -7
  3. package/Editor/Analyzers/BaseCallIlInspector.cs +277 -0
  4. package/Editor/Analyzers/BaseCallIlInspector.cs.meta +11 -0
  5. package/Editor/Analyzers/BaseCallLogMessageParser.cs +295 -0
  6. package/Editor/Analyzers/BaseCallLogMessageParser.cs.meta +11 -0
  7. package/Editor/Analyzers/BaseCallReportAggregator.cs +308 -0
  8. package/Editor/Analyzers/BaseCallReportAggregator.cs.meta +11 -0
  9. package/Editor/Analyzers/BaseCallTypeScanner.cs +110 -0
  10. package/Editor/Analyzers/BaseCallTypeScanner.cs.meta +11 -0
  11. package/Editor/Analyzers/BaseCallTypeScannerCore.cs +562 -0
  12. package/Editor/Analyzers/BaseCallTypeScannerCore.cs.meta +11 -0
  13. package/Editor/Analyzers/DxMessagingConsoleHarvester.cs +1129 -0
  14. package/Editor/Analyzers/DxMessagingConsoleHarvester.cs.meta +11 -0
  15. package/Editor/Analyzers/Microsoft.CodeAnalysis.CSharp.dll.meta +44 -44
  16. package/Editor/Analyzers/Microsoft.CodeAnalysis.dll.meta +44 -44
  17. package/Editor/Analyzers/System.Collections.Immutable.dll.meta +44 -44
  18. package/Editor/Analyzers/System.Reflection.Metadata.dll.meta +44 -44
  19. package/Editor/Analyzers/System.Runtime.CompilerServices.Unsafe.dll.meta +44 -44
  20. package/Editor/Analyzers/WallstopStudios.DxMessaging.Analyzer.dll +0 -0
  21. package/Editor/Analyzers/WallstopStudios.DxMessaging.Analyzer.dll.meta +46 -0
  22. package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll +0 -0
  23. package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll.meta +72 -72
  24. package/Editor/Analyzers.meta +8 -8
  25. package/Editor/AssemblyInfo.cs.meta +11 -3
  26. package/Editor/CustomEditors/MessageAwareComponentFallbackEditor.cs +81 -0
  27. package/Editor/CustomEditors/MessageAwareComponentFallbackEditor.cs.meta +11 -0
  28. package/Editor/CustomEditors/MessageAwareComponentInspectorOverlay.cs +429 -0
  29. package/Editor/CustomEditors/MessageAwareComponentInspectorOverlay.cs.meta +11 -0
  30. package/Editor/CustomEditors/MessagingComponentEditor.cs +1 -1
  31. package/Editor/CustomEditors/MessagingComponentEditor.cs.meta +11 -3
  32. package/Editor/CustomEditors.meta +2 -2
  33. package/Editor/DxMessagingEditorIdle.cs +62 -0
  34. package/Editor/DxMessagingEditorIdle.cs.meta +11 -0
  35. package/Editor/DxMessagingEditorInitializer.cs +112 -15
  36. package/Editor/DxMessagingEditorInitializer.cs.meta +11 -3
  37. package/Editor/DxMessagingEditorLog.cs +32 -0
  38. package/Editor/DxMessagingEditorLog.cs.meta +11 -0
  39. package/Editor/DxMessagingMenu.cs.meta +11 -11
  40. package/Editor/DxMessagingSceneBuildProcessor.cs.meta +11 -11
  41. package/Editor/Settings/DxMessagingBaseCallIgnoreSync.cs +313 -0
  42. package/Editor/Settings/DxMessagingBaseCallIgnoreSync.cs.meta +11 -0
  43. package/Editor/Settings/DxMessagingSettings.cs +261 -11
  44. package/Editor/Settings/DxMessagingSettings.cs.meta +11 -3
  45. package/Editor/Settings/DxMessagingSettingsProvider.cs +50 -33
  46. package/Editor/Settings/DxMessagingSettingsProvider.cs.meta +11 -3
  47. package/Editor/Settings.meta +2 -2
  48. package/Editor/SetupCscRsp.cs +406 -39
  49. package/Editor/SetupCscRsp.cs.meta +11 -3
  50. package/Editor/Testing/MessagingComponentEditorHarness.cs +2 -2
  51. package/Editor/Testing/MessagingComponentEditorHarness.cs.meta +11 -3
  52. package/Editor/Testing.meta +3 -3
  53. package/Editor/WallstopStudios.DxMessaging.Editor.asmdef +14 -14
  54. package/Editor/WallstopStudios.DxMessaging.Editor.asmdef.meta +7 -7
  55. package/Editor.meta +8 -8
  56. package/LICENSE.md +9 -9
  57. package/LICENSE.md.meta +7 -7
  58. package/README.md +940 -900
  59. package/README.md.meta +7 -7
  60. package/Runtime/AssemblyInfo.cs +4 -0
  61. package/Runtime/AssemblyInfo.cs.meta +11 -3
  62. package/Runtime/Core/Attributes/DxAutoConstructorAttribute.cs.meta +11 -3
  63. package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs.meta +11 -3
  64. package/Runtime/Core/Attributes/DxIgnoreMissingBaseCallAttribute.cs +26 -0
  65. package/Runtime/Core/Attributes/DxIgnoreMissingBaseCallAttribute.cs.meta +11 -0
  66. package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs +2 -4
  67. package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs.meta +11 -3
  68. package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs.meta +11 -3
  69. package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs.meta +11 -3
  70. package/Runtime/Core/Attributes/Il2CppSetOptionAttribute.cs +56 -0
  71. package/Runtime/Core/Attributes/Il2CppSetOptionAttribute.cs.meta +11 -0
  72. package/Runtime/Core/Attributes.meta +2 -2
  73. package/Runtime/Core/Configuration/DxMessagingRuntimeSettings.cs +195 -0
  74. package/Runtime/Core/Configuration/DxMessagingRuntimeSettings.cs.meta +11 -0
  75. package/Runtime/Core/Configuration/DxMessagingRuntimeSettingsProvider.cs +179 -0
  76. package/Runtime/Core/Configuration/DxMessagingRuntimeSettingsProvider.cs.meta +11 -0
  77. package/Runtime/Core/Configuration.meta +9 -0
  78. package/Runtime/Core/DataStructure/CyclicBuffer.cs +46 -28
  79. package/Runtime/Core/DataStructure/CyclicBuffer.cs.meta +11 -3
  80. package/Runtime/Core/DataStructure.meta +2 -2
  81. package/Runtime/Core/Diagnostics/MessageEmissionData.cs.meta +11 -3
  82. package/Runtime/Core/Diagnostics/MessageRegistrationData.cs.meta +11 -3
  83. package/Runtime/Core/Diagnostics/MessageRegistrationType.cs.meta +11 -3
  84. package/Runtime/Core/Diagnostics.meta +2 -2
  85. package/Runtime/Core/DxMessagingStaticState.cs +19 -0
  86. package/Runtime/Core/DxMessagingStaticState.cs.meta +11 -11
  87. package/Runtime/Core/Extensions/EnumExtensions.cs +6 -5
  88. package/Runtime/Core/Extensions/EnumExtensions.cs.meta +11 -3
  89. package/Runtime/Core/Extensions/IListExtensions.cs.meta +11 -3
  90. package/Runtime/Core/Extensions/MessageBusExtensions.cs.meta +12 -12
  91. package/Runtime/Core/Extensions/MessageExtensions.cs +0 -60
  92. package/Runtime/Core/Extensions/MessageExtensions.cs.meta +11 -11
  93. package/Runtime/Core/Extensions.meta +8 -8
  94. package/Runtime/Core/Helper/MessageCache.cs +32 -0
  95. package/Runtime/Core/Helper/MessageCache.cs.meta +11 -3
  96. package/Runtime/Core/Helper/MessageHelperIndexer.cs.meta +11 -3
  97. package/Runtime/Core/Helper.meta +2 -2
  98. package/Runtime/Core/IMessage.cs +3 -3
  99. package/Runtime/Core/IMessage.cs.meta +11 -11
  100. package/Runtime/Core/InstanceId.cs +25 -1
  101. package/Runtime/Core/InstanceId.cs.meta +11 -11
  102. package/Runtime/Core/Internal/DxUnsafe.cs +60 -0
  103. package/Runtime/Core/Internal/DxUnsafe.cs.meta +11 -0
  104. package/Runtime/Core/Internal/FlatDispatch.cs +198 -0
  105. package/Runtime/Core/Internal/FlatDispatch.cs.meta +11 -0
  106. package/Runtime/Core/Internal/TypedGlobalSlotIndex.cs +38 -0
  107. package/Runtime/Core/Internal/TypedGlobalSlotIndex.cs.meta +11 -0
  108. package/Runtime/Core/Internal/TypedSlotIndex.cs +81 -0
  109. package/Runtime/Core/Internal/TypedSlotIndex.cs.meta +11 -0
  110. package/Runtime/Core/Internal/TypedSlots.cs +597 -0
  111. package/Runtime/Core/Internal/TypedSlots.cs.meta +11 -0
  112. package/Runtime/Core/Internal.meta +9 -0
  113. package/Runtime/Core/MessageBus/DiagnosticsTarget.cs.meta +11 -11
  114. package/Runtime/Core/MessageBus/GlobalMessageBusProvider.cs.meta +11 -11
  115. package/Runtime/Core/MessageBus/IMessageBus.cs +189 -15
  116. package/Runtime/Core/MessageBus/IMessageBus.cs.meta +11 -11
  117. package/Runtime/Core/MessageBus/IMessageBusProvider.cs.meta +11 -11
  118. package/Runtime/Core/MessageBus/IMessageRegistrationBuilder.cs +1 -0
  119. package/Runtime/Core/MessageBus/IMessageRegistrationBuilder.cs.meta +11 -11
  120. package/Runtime/Core/MessageBus/Internal/BusContextIndex.cs +16 -0
  121. package/Runtime/Core/MessageBus/Internal/BusContextIndex.cs.meta +11 -0
  122. package/Runtime/Core/MessageBus/Internal/BusSinkIndex.cs +40 -0
  123. package/Runtime/Core/MessageBus/Internal/BusSinkIndex.cs.meta +11 -0
  124. package/Runtime/Core/MessageBus/Internal/BusSlots.cs +719 -0
  125. package/Runtime/Core/MessageBus/Internal/BusSlots.cs.meta +11 -0
  126. package/Runtime/Core/MessageBus/Internal/DispatchKind.cs +38 -0
  127. package/Runtime/Core/MessageBus/Internal/DispatchKind.cs.meta +11 -0
  128. package/Runtime/Core/MessageBus/Internal/DispatchPhase.cs +20 -0
  129. package/Runtime/Core/MessageBus/Internal/DispatchPhase.cs.meta +11 -0
  130. package/Runtime/Core/MessageBus/Internal/DispatchVariant.cs +28 -0
  131. package/Runtime/Core/MessageBus/Internal/DispatchVariant.cs.meta +11 -0
  132. package/Runtime/Core/MessageBus/Internal/IEvictableSlot.cs +48 -0
  133. package/Runtime/Core/MessageBus/Internal/IEvictableSlot.cs.meta +11 -0
  134. package/Runtime/Core/MessageBus/Internal/ISweepable.cs +15 -0
  135. package/Runtime/Core/MessageBus/Internal/ISweepable.cs.meta +11 -0
  136. package/Runtime/Core/MessageBus/Internal/RegistrationMethodAxes.cs +222 -0
  137. package/Runtime/Core/MessageBus/Internal/RegistrationMethodAxes.cs.meta +11 -0
  138. package/Runtime/Core/MessageBus/Internal/SlotKey.cs +192 -0
  139. package/Runtime/Core/MessageBus/Internal/SlotKey.cs.meta +11 -0
  140. package/Runtime/Core/MessageBus/Internal.meta +9 -0
  141. package/Runtime/Core/MessageBus/MessageBus.cs +5366 -3838
  142. package/Runtime/Core/MessageBus/MessageBus.cs.meta +11 -11
  143. package/Runtime/Core/MessageBus/MessageBusRebindMode.cs.meta +11 -11
  144. package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs +187 -14
  145. package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs.meta +11 -11
  146. package/Runtime/Core/MessageBus/MessagingRegistration.cs.meta +11 -11
  147. package/Runtime/Core/MessageBus/RegistrationLog.cs.meta +11 -11
  148. package/Runtime/Core/MessageBus.meta +8 -8
  149. package/Runtime/Core/MessageHandler.cs +2399 -1042
  150. package/Runtime/Core/MessageHandler.cs.meta +11 -11
  151. package/Runtime/Core/MessageRegistrationHandle.cs.meta +11 -11
  152. package/Runtime/Core/MessageRegistrationToken.cs +429 -44
  153. package/Runtime/Core/MessageRegistrationToken.cs.meta +11 -11
  154. package/Runtime/Core/Messages/GlobalStringMessage.cs.meta +11 -3
  155. package/Runtime/Core/Messages/IBroadcastMessage.cs.meta +11 -11
  156. package/Runtime/Core/Messages/ITargetedMessage.cs.meta +11 -11
  157. package/Runtime/Core/Messages/IUntargetedMessage.cs.meta +11 -11
  158. package/Runtime/Core/Messages/ReflexiveMessage.cs.meta +11 -3
  159. package/Runtime/Core/Messages/SourcedStringMessage.cs.meta +11 -11
  160. package/Runtime/Core/Messages/StringMessage.cs.meta +11 -3
  161. package/Runtime/Core/Messages.meta +8 -8
  162. package/Runtime/Core/MessagingDebug.cs.meta +11 -11
  163. package/Runtime/Core/Pooling/CollectionPool.cs +266 -0
  164. package/Runtime/Core/Pooling/CollectionPool.cs.meta +11 -0
  165. package/Runtime/Core/Pooling/CollectionPoolDiagnostics.cs +30 -0
  166. package/Runtime/Core/Pooling/CollectionPoolDiagnostics.cs.meta +11 -0
  167. package/Runtime/Core/Pooling/DxPools.cs +157 -0
  168. package/Runtime/Core/Pooling/DxPools.cs.meta +11 -0
  169. package/Runtime/Core/Pooling/EvictionPlayerLoopHook.cs +106 -0
  170. package/Runtime/Core/Pooling/EvictionPlayerLoopHook.cs.meta +11 -0
  171. package/Runtime/Core/Pooling/IDxMessagingClock.cs +18 -0
  172. package/Runtime/Core/Pooling/IDxMessagingClock.cs.meta +11 -0
  173. package/Runtime/Core/Pooling/PoolDiagnosticsSnapshot.cs +55 -0
  174. package/Runtime/Core/Pooling/PoolDiagnosticsSnapshot.cs.meta +11 -0
  175. package/Runtime/Core/Pooling/StopwatchClock.cs +27 -0
  176. package/Runtime/Core/Pooling/StopwatchClock.cs.meta +11 -0
  177. package/Runtime/Core/Pooling/UnityRealtimeClock.cs +31 -0
  178. package/Runtime/Core/Pooling/UnityRealtimeClock.cs.meta +11 -0
  179. package/Runtime/Core/Pooling.meta +9 -0
  180. package/Runtime/Core.meta +8 -8
  181. package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs.meta +12 -12
  182. package/Runtime/Unity/DxMessagingRuntimeInitializer.cs.meta +11 -11
  183. package/Runtime/Unity/InitialGlobalMessageBusProvider.cs.meta +12 -12
  184. package/Runtime/Unity/Integrations/Reflex/AssemblyInfo.cs.meta +11 -3
  185. package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs +73 -0
  186. package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs.meta +11 -11
  187. package/Runtime/Unity/Integrations/Reflex/WallstopStudios.DxMessaging.Reflex.asmdef +20 -20
  188. package/Runtime/Unity/Integrations/Reflex/WallstopStudios.DxMessaging.Reflex.asmdef.meta +7 -7
  189. package/Runtime/Unity/Integrations/Reflex.meta +8 -8
  190. package/Runtime/Unity/Integrations/VContainer/AssemblyInfo.cs.meta +11 -3
  191. package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs +109 -1
  192. package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs.meta +11 -11
  193. package/Runtime/Unity/Integrations/VContainer/WallstopStudios.DxMessaging.VContainer.asmdef +30 -30
  194. package/Runtime/Unity/Integrations/VContainer/WallstopStudios.DxMessaging.VContainer.asmdef.meta +7 -7
  195. package/Runtime/Unity/Integrations/VContainer.meta +8 -8
  196. package/Runtime/Unity/Integrations/Zenject/AssemblyInfo.cs.meta +11 -3
  197. package/Runtime/Unity/Integrations/Zenject/WallstopStudios.DxMessaging.Zenject.asmdef +30 -30
  198. package/Runtime/Unity/Integrations/Zenject/WallstopStudios.DxMessaging.Zenject.asmdef.meta +7 -7
  199. package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs +79 -1
  200. package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs.meta +11 -11
  201. package/Runtime/Unity/Integrations/Zenject.meta +8 -8
  202. package/Runtime/Unity/Integrations.meta +8 -8
  203. package/Runtime/Unity/MessageAwareComponent.cs +74 -0
  204. package/Runtime/Unity/MessageAwareComponent.cs.meta +11 -11
  205. package/Runtime/Unity/MessageBusProviderHandle.cs.meta +12 -12
  206. package/Runtime/Unity/MessagingComponent.cs +43 -10
  207. package/Runtime/Unity/MessagingComponent.cs.meta +11 -11
  208. package/Runtime/Unity/MessagingComponentInstaller.cs.meta +12 -12
  209. package/Runtime/Unity/ScriptableMessageBusProvider.cs.meta +12 -12
  210. package/Runtime/Unity.meta +8 -8
  211. package/Runtime/WallstopStudios.DxMessaging.asmdef +14 -14
  212. package/Runtime/WallstopStudios.DxMessaging.asmdef.meta +7 -7
  213. package/Runtime.meta +8 -8
  214. package/Samples~/DI/Prefabs/MessagingInstallerSample.prefab +98 -98
  215. package/Samples~/DI/Prefabs/MessagingInstallerSample.prefab.meta +7 -7
  216. package/Samples~/DI/Prefabs.meta +8 -8
  217. package/Samples~/DI/Providers/GlobalMessageBusProvider.asset +14 -14
  218. package/Samples~/DI/Providers/GlobalMessageBusProvider.asset.meta +8 -8
  219. package/Samples~/DI/Providers/InitialGlobalMessageBusProvider.asset +14 -14
  220. package/Samples~/DI/Providers/InitialGlobalMessageBusProvider.asset.meta +8 -8
  221. package/Samples~/DI/Providers.meta +8 -8
  222. package/Samples~/DI/README.md +51 -51
  223. package/Samples~/DI/README.md.meta +7 -7
  224. package/Samples~/DI/Reflex/SampleInstaller.cs +7 -0
  225. package/Samples~/DI/Reflex/SampleInstaller.cs.meta +11 -11
  226. package/Samples~/DI/Reflex.meta +8 -8
  227. package/Samples~/DI/VContainer/SampleLifetimeScope.cs +6 -1
  228. package/Samples~/DI/VContainer/SampleLifetimeScope.cs.meta +11 -11
  229. package/Samples~/DI/VContainer.meta +8 -8
  230. package/Samples~/DI/Zenject/SampleInstaller.cs +8 -0
  231. package/Samples~/DI/Zenject/SampleInstaller.cs.meta +11 -11
  232. package/Samples~/DI/Zenject.meta +8 -8
  233. package/Samples~/DI.meta +8 -8
  234. package/Samples~/Mini Combat/Boot.cs.meta +11 -11
  235. package/Samples~/Mini Combat/Enemy.cs.meta +11 -11
  236. package/Samples~/Mini Combat/Messages.cs.meta +11 -11
  237. package/Samples~/Mini Combat/Player.cs.meta +11 -11
  238. package/Samples~/Mini Combat/README.md +324 -323
  239. package/Samples~/Mini Combat/README.md.meta +7 -7
  240. package/Samples~/Mini Combat/UIOverlay.cs.meta +11 -11
  241. package/Samples~/Mini Combat/Walkthrough.md +430 -430
  242. package/Samples~/Mini Combat/Walkthrough.md.meta +7 -7
  243. package/Samples~/Mini Combat/WallstopStudios.DxMessaging.MiniCombat.Sample.asmdef +13 -13
  244. package/Samples~/Mini Combat/WallstopStudios.DxMessaging.MiniCombat.Sample.asmdef.meta +7 -7
  245. package/Samples~/Mini Combat.meta +8 -8
  246. package/Samples~/UI Buttons + Inspector/DiagnosticsEnabler.cs.meta +11 -11
  247. package/Samples~/UI Buttons + Inspector/Messages.cs.meta +11 -11
  248. package/Samples~/UI Buttons + Inspector/MessagingObserver.cs.meta +11 -11
  249. package/Samples~/UI Buttons + Inspector/README.md +210 -209
  250. package/Samples~/UI Buttons + Inspector/README.md.meta +7 -7
  251. package/Samples~/UI Buttons + Inspector/UIButtonEmitter.cs.meta +11 -11
  252. package/Samples~/UI Buttons + Inspector/WallstopStudios.DxMessaging.UIButtons.Sample.asmdef +13 -13
  253. package/Samples~/UI Buttons + Inspector/WallstopStudios.DxMessaging.UIButtons.Sample.asmdef.meta +7 -7
  254. package/Samples~/UI Buttons + Inspector.meta +8 -8
  255. package/SourceGenerators/Directory.Build.props +50 -3
  256. package/SourceGenerators/Directory.Build.props.meta +7 -7
  257. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoConstructorGenerator.cs +96 -63
  258. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoConstructorGenerator.cs.meta +11 -11
  259. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxMessageIdGenerator.cs +745 -87
  260. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxMessageIdGenerator.cs.meta +11 -3
  261. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj +39 -46
  262. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj.meta +7 -7
  263. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.meta +8 -8
  264. package/SourceGenerators/global.json +7 -0
  265. package/SourceGenerators/global.json.meta +7 -0
  266. package/SourceGenerators.meta +8 -8
  267. package/Third Party Notices.md +3 -3
  268. package/Third Party Notices.md.meta +7 -7
  269. package/package.json +102 -92
  270. package/package.json.meta +7 -7
@@ -1,430 +1,430 @@
1
- # Mini Combat Walkthrough
2
-
3
- > **Deep Dive**: Ready to understand HOW it works? This walkthrough explains every line of code and shows the complete message flow.
4
-
5
- ## Who This Is For
6
-
7
- - **You've imported and run the sample** - now you want to understand it
8
- - **You want to build your own** - need to see the patterns in action
9
- - **You're debugging something** - need to understand the flow
10
-
11
- **Haven't run the sample yet?** Go back to [the sample README](README.md) and press Play first. Come back when you've seen it work.
12
-
13
- ---
14
-
15
- ## What You'll Understand By The End
16
-
17
- After reading this walkthrough, you'll know:
18
-
19
- 1. **Why each message type was chosen** - the reasoning behind Untargeted vs Targeted vs Broadcast
20
- 2. **How the code flows** - step-by-step from [Boot.cs](./Boot.cs) through every script
21
- 3. **Common patterns** - Observer, Broadcaster, Orchestrator, and more
22
- 4. **Debugging strategies** - how to find and fix issues
23
- 5. **How to extend it** - add your own messages and handlers
24
-
25
- **Estimated time:** 20-30 minutes for thorough understanding
26
-
27
- ---
28
-
29
- ## Table of Contents
30
-
31
- - [Script Overview](#script-overview)
32
- - [Complete Message Flow](#complete-message-flow)
33
- - [Scene 1: Settings Update](#scene-1-settings-update)
34
- - [Scene 2: Healing the Player](#scene-2-healing-the-player)
35
- - [Scene 3: Enemy Takes Damage](#scene-3-enemy-takes-damage)
36
- - [Understanding Targeting Decisions](#understanding-targeting-decisions)
37
- - [Debugging Tips](#debugging-tips)
38
- - [Common Patterns Explained](#common-patterns-explained)
39
-
40
- ---
41
-
42
- ## Script Overview
43
-
44
- Let's understand what each script does:
45
-
46
- ### [Messages.cs](./Messages.cs)
47
-
48
- **Purpose**: Defines all message types used in the sample
49
-
50
- ```csharp
51
- // Message definitions (simplified for explanation)
52
- - VideoSettingsChanged (untargeted) // Global setting anyone can listen to
53
- - Heal (targeted) // Directed at a specific component
54
- - TookDamage (broadcast) // Announced to all interested parties
55
- ```
56
-
57
- **Why separate file?** Keeping messages in one place makes them easy to find and prevents circular dependencies.
58
-
59
- ### [Player.cs](./Player.cs)
60
-
61
- **What it does**: Listens for healing messages targeted specifically at this player
62
-
63
- **Key code pattern**:
64
-
65
- - Registers to receive `Heal` messages **targeted at its Component**
66
- - Only *this specific Player instance* receives the heal
67
- - Other Player instances in the scene won't be affected
68
-
69
- **Real-world analogy**: Like having your name called in a doctor's officeonly you respond.
70
-
71
- ### [Enemy.cs](./Enemy.cs)
72
-
73
- **What it does**: Broadcasts when it takes damage
74
-
75
- **Key code pattern**:
76
-
77
- - Emits `TookDamage` as a **broadcast from its GameObject**
78
- - Any listener interested in damage events will hear it
79
- - The Enemy doesn't need to know who's listening
80
-
81
- **Real-world analogy**: Like ringing a bellanyone nearby can hear it.
82
-
83
- ### [UIOverlay.cs](./UIOverlay.cs)
84
-
85
- **What it does**: Monitors game events and updates the UI
86
-
87
- **Key code pattern**:
88
-
89
- - Listens to `VideoSettingsChanged` (untargeted)
90
- - Listens to `TookDamage` from **all sources** using `RegisterBroadcastWithoutSource`
91
- - Acts as a "dashboard" showing what's happening in the game
92
-
93
- **Real-world analogy**: Like a news reporter watching everything and reporting it.
94
-
95
- ### [Boot.cs](./Boot.cs)
96
-
97
- **What it does**: Starts the demo by simulating a sequence of events
98
-
99
- **Key code pattern**:
100
-
101
- - Sends messages to trigger the other scripts
102
- - Acts as a "director" orchestrating the demo
103
-
104
- ---
105
-
106
- ## Complete Message Flow
107
-
108
- Here's the full sequence that happens when you press Play:
109
-
110
- ```mermaid
111
- sequenceDiagram
112
- participant Boot
113
- participant UIOverlay
114
- participant Player
115
- participant Enemy
116
-
117
- Note over Boot: STEP 1: Boot starts
118
- Boot->>UIOverlay: VideoSettingsChanged (Untargeted)
119
- Note over UIOverlay: Rebuilds UI
120
-
121
- Note over Boot: STEP 2: Boot sends Heal
122
- Boot->>Player: Heal (Targeted)
123
- Note over Player: Increases HP by heal amount
124
-
125
- Note over Enemy: STEP 3: Enemy broadcasts
126
- Enemy->>UIOverlay: TookDamage (Broadcast)
127
- Note over UIOverlay: Shows damage notification
128
- ```
129
-
130
- ---
131
-
132
- ## Scene 1: Settings Update
133
-
134
- ### What Happens
135
-
136
- Boot sends a `VideoSettingsChanged` message (untargeted).
137
-
138
- ### Why Untargeted
139
-
140
- Settings changes are **global events**—they don't target anyone specifically. Anyone interested in settings can listen.
141
-
142
- ### The Code Flow
143
-
144
- 1. **[Boot.cs](./Boot.cs)** calls: `var settings = new VideoSettingsChanged(); settings.Emit();`
145
- 1. **[UIOverlay.cs](./UIOverlay.cs)** receives it through its registered handler
146
- 1. **UIOverlay** rebuilds the UI with new settings
147
-
148
- ### Developer Notes
149
-
150
- #### When to use untargeted messages:
151
-
152
- - Global game state changes (settings, game mode, pause state)
153
- - Events that multiple unrelated systems might care about
154
- - Configuration updates
155
-
156
- ##### Pros:
157
-
158
- - Simple and fast
159
- - No need to know who's listening
160
- - Easy to add new listeners
161
-
162
- ###### Cons:
163
-
164
- - No targetingeveryone gets it
165
- - Can't send to just one specific object
166
-
167
- ---
168
-
169
- ## Scene 2: Healing the Player
170
-
171
- ### What Happens
172
-
173
- Boot sends a `Heal` message **targeted directly at the Player Component**.
174
-
175
- ### Why Targeted
176
-
177
- We want to heal **one specific player**, not all players in the scene.
178
-
179
- ### The Code Flow
180
-
181
- 1. **[Boot.cs](./Boot.cs)** finds the Player Component reference
182
- 1. **[Boot.cs](./Boot.cs)** calls: `var heal = new Heal(amount); heal.EmitComponentTargeted(targetComponent);`
183
- 1. **Only the targeted [Player.cs](./Player.cs)** receives it through its handler
184
- 1. **Player** increases its HP
185
-
186
- ### Developer Notes
187
-
188
- #### When to use targeted messages:
189
-
190
- - Actions directed at specific objects (heal this player, damage this enemy)
191
- - Commands for specific systems (open this door, activate this switch)
192
- - Any time you need precision delivery
193
-
194
- ##### Pros:
195
-
196
- - Precise delivery to one recipient
197
- - Multiple instances can exist without crosstalk
198
- - Clear intent in code
199
-
200
- ###### Cons:
201
-
202
- - Need a reference to the target
203
- - Can't easily notify multiple targets
204
-
205
- ---
206
-
207
- ## Scene 3: Enemy Takes Damage
208
-
209
- ### What Happens
210
-
211
- Enemy broadcasts a `TookDamage` message from its GameObject.
212
-
213
- ### Why Broadcast
214
-
215
- The Enemy doesn't know (or care) who needs to know about the damage. It just announces it.
216
-
217
- ### The Code Flow
218
-
219
- 1. **[Enemy.cs](./Enemy.cs)** detects it took damage
220
- 1. **Enemy** calls: `this.EmitBroadcast(new TookDamage(amount))`
221
- 1. **UIOverlay** receives it via `RegisterBroadcastWithoutSource`
222
- 1. **UIOverlay** displays the damage event
223
-
224
- ### Developer Notes
225
-
226
- #### When to use broadcast messages:
227
-
228
- - Events that multiple systems might monitor (damage, death, score)
229
- - Audio triggers (play sound when anything explodes)
230
- - Analytics/logging systems
231
- - UI notifications
232
-
233
- ##### Pros:
234
-
235
- - Publisher doesn't need to know about subscribers
236
- - Easy to add new listeners without modifying emitter
237
- - Great for cross-cutting concerns (audio, VFX, analytics)
238
-
239
- ###### Cons:
240
-
241
- - Less efficient than targeted messages
242
- - Every listener is notified (can't filter by source unless registered specifically)
243
-
244
- ---
245
-
246
- ## Understanding Targeting Decisions
247
-
248
- ### Why Player Uses Component-Targeted Registration
249
-
250
- ```csharp
251
- // Player.cs registers like this:
252
- token.RegisterComponentTargeted<Heal>(this, OnHeal);
253
- ```
254
-
255
- #### Reasoning:
256
-
257
- - Multiple Player instances might exist (multiplayer, AI companions)
258
- - Each Player should only respond to heals directed at **itself**
259
- - Component-level targeting provides this precision
260
-
261
- ##### What if we used untargeted instead?
262
-
263
- - Problem: ALL players would be healed simultaneously
264
- - Not realistic for gameplay
265
- - Hard to control individual player states
266
-
267
- ### Why UIOverlay Uses Broadcast Without Source
268
-
269
- ```csharp
270
- // UIOverlay.cs registers like this:
271
- token.RegisterBroadcastWithoutSource<TookDamage>(OnTookDamage);
272
- ```
273
-
274
- #### Reasoning:
275
-
276
- - UI needs to monitor **all damage events** in the game
277
- - Doesn't matter which enemy was damaged
278
- - Acts as a global observer
279
-
280
- ##### Alternative approaches:
281
-
282
- - `RegisterGameObjectBroadcast`: Listen only to broadcasts from specific GameObject
283
- - `RegisterComponentBroadcast`: Listen only to broadcasts from specific Component
284
-
285
- ###### When to use each:
286
-
287
- | Method | Use Case | Example |
288
- |--------|----------|---------|
289
- | `RegisterBroadcastWithoutSource` | Monitor all broadcasts of this type | Combat log showing all damage |
290
- | `RegisterGameObjectBroadcast` | Monitor broadcasts from specific GameObject | Health bar for one enemy |
291
- | `RegisterComponentBroadcast` | Monitor broadcasts from specific Component | Track specific weapon's fire events |
292
-
293
- ---
294
-
295
- ## Debugging Tips
296
-
297
- ### Enable Diagnostics
298
-
299
- 1. Select any GameObject with `MessagingComponent`
300
- 1. In the Inspector, find the MessagingComponent
301
- 1. Check the **"Enable Diagnostics"** box
302
- 1. Press Play
303
-
304
- #### What you'll see:
305
-
306
- - Real-time log of messages sent and received
307
- - Message types and payloads
308
- - Source and target information
309
- - Timing information
310
-
311
- ### Debugging Checklist
312
-
313
- #### Message not received?
314
-
315
- - [ ] Is `MessagingComponent` attached to the GameObject?
316
- - [ ] Did you call `MessagingComponent.Create(this)` to get a token?
317
- - [ ] Is the handler method registered correctly?
318
- - [ ] Does the message type match exactly?
319
- - [ ] Is the targeting correct (Component vs GameObject vs Untargeted)?
320
-
321
- ##### Message received by wrong object?
322
-
323
- - [ ] Check if using Broadcast when you meant Targeted
324
- - [ ] Verify Component vs GameObject targeting
325
- - [ ] Check registration method (`RegisterComponent` vs `RegisterGameObject`)
326
-
327
- ###### Message sent but nothing happens?
328
-
329
- - [ ] Verify handler method signature matches
330
- - [ ] Check if GameObject is active
331
- - [ ] Ensure Component is enabled
332
- - [ ] Look for exceptions in Console
333
-
334
- ---
335
-
336
- ## Common Patterns Explained
337
-
338
- ### Pattern 1: The Observer (UIOverlay)
339
-
340
- **What**: A component that listens to many events without being directly involved
341
-
342
- **Use for**: UI, analytics, audio, logging
343
-
344
- **Key characteristic**: Uses `RegisterBroadcastWithoutSource` to monitor everything
345
-
346
- ### Pattern 2: The Direct Recipient (Player)
347
-
348
- **What**: A component that receives targeted instructions
349
-
350
- **Use for**: Entities receiving commands, objects being modified
351
-
352
- **Key characteristic**: Uses `RegisterComponent` for precise delivery
353
-
354
- ### Pattern 3: The Broadcaster (Enemy)
355
-
356
- **What**: A component that announces events without knowing who's listening
357
-
358
- **Use for**: Events that multiple systems care about
359
-
360
- **Key characteristic**: Uses `EmitBroadcast` to send messages
361
-
362
- ### Pattern 4: The Orchestrator (Boot)
363
-
364
- **What**: A component that coordinates by sending multiple messages
365
-
366
- **Use for**: Game flow, cutscenes, tutorials, state machines
367
-
368
- **Key characteristic**: Publishes various message types to drive the system
369
-
370
- ---
371
-
372
- ## Key Takeaways
373
-
374
- ### For Beginners
375
-
376
- 1. **Messages replace direct references**: Instead of `player.Heal()`, use messages
377
- 1. **Three targeting types**: Untargeted (everyone), Targeted (someone specific), Broadcast (anyone listening)
378
- 1. **MessagingComponent is required**: It manages the lifecycle of your subscriptions
379
- 1. **Diagnostics are your friend**: Always enable them when learning
380
-
381
- ### For Intermediate Developers
382
-
383
- 1. **Choose targeting carefully**: Match the message type to your use case
384
- 1. **Broadcast doesn't mean inefficient**: DxMessaging is highly optimized
385
- 1. **Tokens prevent memory leaks**: They auto-unregister when destroyed
386
- 1. **Assembly definitions matter**: Configure them correctly for separate assemblies
387
-
388
- ### For Advanced Developers
389
-
390
- 1. **Source-filtered broadcasts exist**: Use `RegisterGameObjectBroadcast` for efficiency
391
- 1. **Message order can be controlled**: See the Interceptors & Ordering documentation
392
- 1. **Performance considerations**: Targeted > Broadcast in terms of overhead
393
- 1. **Consider message granularity**: Too many message types = harder maintenance
394
-
395
- ---
396
-
397
- ## What's Next
398
-
399
- ### Experiment and Extend
400
-
401
- Try modifying the sample:
402
-
403
- - Add a second Player and see targeted messages in action
404
- - Create a `PlayerDied` broadcast and handle it in multiple places
405
- - Add a UI button that sends messages when clicked
406
- - Implement a damage-over-time system using messages
407
-
408
- ### Learn More
409
-
410
- - **[Message Types Documentation](../../docs/concepts/message-types.md)** - Complete message type reference
411
- - **[Targeting and Context Guide](../../docs/concepts/targeting-and-context.md)** - Deep dive into targeting
412
- - **[Patterns Guide](../../docs/guides/patterns.md)** - Common messaging patterns
413
- - **[Performance Guide](../../docs/architecture/performance.md)** - Optimization tips
414
-
415
- ---
416
-
417
- ## Quick Reference Card
418
-
419
- | Want to... | Use... | Example |
420
- |------------|--------|---------|
421
- | Send to everyone | Untargeted | `var paused = new GamePaused(); paused.Emit();` |
422
- | Send to specific Component | Targeted | `var heal = new Heal(10); heal.EmitComponentTargeted(playerComponent);` |
423
- | Announce an event | Broadcast | `this.EmitBroadcast(new Exploded())` |
424
- | Listen to everything | `RegisterBroadcastWithoutSource` | `token.RegisterBroadcastWithoutSource<Damage>(OnDamage)` |
425
- | Listen to specific source | `RegisterComponentBroadcast` | `token.RegisterComponentBroadcast<Fire>(weapon, OnFire)` |
426
- | Receive targeted messages | `RegisterComponentTargeted` | `token.RegisterComponentTargeted<Heal>(this, OnHeal)` |
427
-
428
- ---
429
-
430
- **Remember**: Keep Player, Enemy, and UIOverlay GameObjects each with a `MessagingComponent` attached, and enable diagnostics to observe message traffic.
1
+ # Mini Combat Walkthrough
2
+
3
+ > **Deep Dive**: Ready to understand HOW it works? This walkthrough explains every line of code and shows the complete message flow.
4
+
5
+ ## Who This Is For
6
+
7
+ - [x] **You've imported and run the sample** - now you want to understand it
8
+ - [x] **You want to build your own** - need to see the patterns in action
9
+ - [x] **You're debugging something** - need to understand the flow
10
+
11
+ **Haven't run the sample yet?** Go back to [the sample README](README.md) and press Play first. Come back when you've seen it work.
12
+
13
+ ---
14
+
15
+ ## What You'll Understand By The End
16
+
17
+ After reading this walkthrough, you'll know:
18
+
19
+ 1. **Why each message type was chosen** - the reasoning behind Untargeted vs Targeted vs Broadcast
20
+ 1. **How the code flows** - step-by-step from [Boot.cs](./Boot.cs) through every script
21
+ 1. **Common patterns** - Observer, Broadcaster, Orchestrator, and more
22
+ 1. **Debugging strategies** - how to find and fix issues
23
+ 1. **How to extend it** - add your own messages and handlers
24
+
25
+ **Estimated time:** 20-30 minutes for thorough understanding
26
+
27
+ ---
28
+
29
+ ## Table of Contents
30
+
31
+ - [Script Overview](#script-overview)
32
+ - [Complete Message Flow](#complete-message-flow)
33
+ - [Scene 1: Settings Update](#scene-1-settings-update)
34
+ - [Scene 2: Healing the Player](#scene-2-healing-the-player)
35
+ - [Scene 3: Enemy Takes Damage](#scene-3-enemy-takes-damage)
36
+ - [Understanding Targeting Decisions](#understanding-targeting-decisions)
37
+ - [Debugging Tips](#debugging-tips)
38
+ - [Common Patterns Explained](#common-patterns-explained)
39
+
40
+ ---
41
+
42
+ ## Script Overview
43
+
44
+ Let's understand what each script does:
45
+
46
+ ### [Messages.cs](./Messages.cs)
47
+
48
+ **Purpose**: Defines all message types used in the sample
49
+
50
+ ```csharp
51
+ // Message definitions (simplified for explanation)
52
+ - VideoSettingsChanged (untargeted) // Global setting anyone can listen to
53
+ - Heal (targeted) // Directed at a specific component
54
+ - TookDamage (broadcast) // Announced to all interested parties
55
+ ```
56
+
57
+ **Why separate file?** Keeping messages in one place makes them easy to find and prevents circular dependencies.
58
+
59
+ ### [Player.cs](./Player.cs)
60
+
61
+ **What it does**: Listens for healing messages targeted specifically at this player
62
+
63
+ **Key code pattern**:
64
+
65
+ - Registers to receive `Heal` messages **targeted at its Component**
66
+ - Only *this specific Player instance* receives the heal
67
+ - Other Player instances in the scene won't be affected
68
+
69
+ **Real-world analogy**: Like having your name called in a doctor's office -- only you respond.
70
+
71
+ ### [Enemy.cs](./Enemy.cs)
72
+
73
+ **What it does**: Broadcasts when it takes damage
74
+
75
+ **Key code pattern**:
76
+
77
+ - Emits `TookDamage` as a **broadcast from its GameObject**
78
+ - Any listener interested in damage events will hear it
79
+ - The Enemy doesn't need to know who's listening
80
+
81
+ **Real-world analogy**: Like ringing a bell -- anyone nearby can hear it.
82
+
83
+ ### [UIOverlay.cs](./UIOverlay.cs)
84
+
85
+ **What it does**: Monitors game events and updates the UI
86
+
87
+ **Key code pattern**:
88
+
89
+ - Listens to `VideoSettingsChanged` (untargeted)
90
+ - Listens to `TookDamage` from **all sources** using `RegisterBroadcastWithoutSource`
91
+ - Acts as a "dashboard" showing what's happening in the game
92
+
93
+ **Real-world analogy**: Like a news reporter watching everything and reporting it.
94
+
95
+ ### [Boot.cs](./Boot.cs)
96
+
97
+ **What it does**: Starts the demo by simulating a sequence of events
98
+
99
+ **Key code pattern**:
100
+
101
+ - Sends messages to trigger the other scripts
102
+ - Acts as a "director" orchestrating the demo
103
+
104
+ ---
105
+
106
+ ## Complete Message Flow
107
+
108
+ Here's the full sequence that happens when you press Play:
109
+
110
+ ```mermaid
111
+ sequenceDiagram
112
+ participant Boot
113
+ participant UIOverlay
114
+ participant Player
115
+ participant Enemy
116
+
117
+ Note over Boot: STEP 1: Boot starts
118
+ Boot->>UIOverlay: VideoSettingsChanged (Untargeted)
119
+ Note over UIOverlay: Rebuilds UI
120
+
121
+ Note over Boot: STEP 2: Boot sends Heal
122
+ Boot->>Player: Heal (Targeted)
123
+ Note over Player: Increases HP by heal amount
124
+
125
+ Note over Enemy: STEP 3: Enemy broadcasts
126
+ Enemy->>UIOverlay: TookDamage (Broadcast)
127
+ Note over UIOverlay: Shows damage notification
128
+ ```
129
+
130
+ ---
131
+
132
+ ## Scene 1: Settings Update
133
+
134
+ ### What Happens
135
+
136
+ Boot sends a `VideoSettingsChanged` message (untargeted).
137
+
138
+ ### Why Untargeted
139
+
140
+ Settings changes are **global events** -- they don't target anyone specifically. Anyone interested in settings can listen.
141
+
142
+ ### The Code Flow
143
+
144
+ 1. **[Boot.cs](./Boot.cs)** calls: `var settings = new VideoSettingsChanged(); settings.Emit();`
145
+ 1. **[UIOverlay.cs](./UIOverlay.cs)** receives it through its registered handler
146
+ 1. **UIOverlay** rebuilds the UI with new settings
147
+
148
+ ### Developer Notes
149
+
150
+ #### When to use untargeted messages:
151
+
152
+ - Global game state changes (settings, game mode, pause state)
153
+ - Events that multiple unrelated systems might care about
154
+ - Configuration updates
155
+
156
+ ##### Pros:
157
+
158
+ - Simple and fast
159
+ - No need to know who's listening
160
+ - Easy to add new listeners
161
+
162
+ ###### Cons:
163
+
164
+ - No targeting -- everyone gets it
165
+ - Can't send to just one specific object
166
+
167
+ ---
168
+
169
+ ## Scene 2: Healing the Player
170
+
171
+ ### What Happens
172
+
173
+ Boot sends a `Heal` message **targeted directly at the Player Component**.
174
+
175
+ ### Why Targeted
176
+
177
+ We want to heal **one specific player**, not all players in the scene.
178
+
179
+ ### The Code Flow
180
+
181
+ 1. **[Boot.cs](./Boot.cs)** finds the Player Component reference
182
+ 1. **[Boot.cs](./Boot.cs)** calls: `var heal = new Heal(amount); heal.EmitComponentTargeted(targetComponent);`
183
+ 1. **Only the targeted [Player.cs](./Player.cs)** receives it through its handler
184
+ 1. **Player** increases its HP
185
+
186
+ ### Developer Notes
187
+
188
+ #### When to use targeted messages:
189
+
190
+ - Actions directed at specific objects (heal this player, damage this enemy)
191
+ - Commands for specific systems (open this door, activate this switch)
192
+ - Any time you need precision delivery
193
+
194
+ ##### Pros:
195
+
196
+ - Precise delivery to one recipient
197
+ - Multiple instances can exist without crosstalk
198
+ - Clear intent in code
199
+
200
+ ###### Cons:
201
+
202
+ - Need a reference to the target
203
+ - Can't easily notify multiple targets
204
+
205
+ ---
206
+
207
+ ## Scene 3: Enemy Takes Damage
208
+
209
+ ### What Happens
210
+
211
+ Enemy broadcasts a `TookDamage` message from its GameObject.
212
+
213
+ ### Why Broadcast
214
+
215
+ The Enemy doesn't know (or care) who needs to know about the damage. It just announces it.
216
+
217
+ ### The Code Flow
218
+
219
+ 1. **[Enemy.cs](./Enemy.cs)** detects it took damage
220
+ 1. **Enemy** calls: `this.EmitBroadcast(new TookDamage(amount))`
221
+ 1. **UIOverlay** receives it via `RegisterBroadcastWithoutSource`
222
+ 1. **UIOverlay** displays the damage event
223
+
224
+ ### Developer Notes
225
+
226
+ #### When to use broadcast messages:
227
+
228
+ - Events that multiple systems might monitor (damage, death, score)
229
+ - Audio triggers (play sound when anything explodes)
230
+ - Analytics/logging systems
231
+ - UI notifications
232
+
233
+ ##### Pros:
234
+
235
+ - Publisher doesn't need to know about subscribers
236
+ - Easy to add new listeners without modifying emitter
237
+ - Great for cross-cutting concerns (audio, VFX, analytics)
238
+
239
+ ###### Cons:
240
+
241
+ - Less efficient than targeted messages
242
+ - Every listener is notified (can't filter by source unless registered specifically)
243
+
244
+ ---
245
+
246
+ ## Understanding Targeting Decisions
247
+
248
+ ### Why Player Uses Component-Targeted Registration
249
+
250
+ ```csharp
251
+ // Player.cs registers like this:
252
+ token.RegisterComponentTargeted<Heal>(this, OnHeal);
253
+ ```
254
+
255
+ #### Reasoning:
256
+
257
+ - Multiple Player instances might exist (multiplayer, AI companions)
258
+ - Each Player should only respond to heals directed at **itself**
259
+ - Component-level targeting provides this precision
260
+
261
+ ##### What if we used untargeted instead?
262
+
263
+ - Problem: ALL players would be healed simultaneously
264
+ - Not realistic for gameplay
265
+ - Hard to control individual player states
266
+
267
+ ### Why UIOverlay Uses Broadcast Without Source
268
+
269
+ ```csharp
270
+ // UIOverlay.cs registers like this:
271
+ token.RegisterBroadcastWithoutSource<TookDamage>(OnTookDamage);
272
+ ```
273
+
274
+ #### Reasoning:
275
+
276
+ - UI needs to monitor **all damage events** in the game
277
+ - Doesn't matter which enemy was damaged
278
+ - Acts as a global observer
279
+
280
+ ##### Alternative approaches:
281
+
282
+ - `RegisterGameObjectBroadcast`: Listen only to broadcasts from specific GameObject
283
+ - `RegisterComponentBroadcast`: Listen only to broadcasts from specific Component
284
+
285
+ ###### When to use each:
286
+
287
+ | Method | Use Case | Example |
288
+ |--------|----------|---------|
289
+ | `RegisterBroadcastWithoutSource` | Monitor all broadcasts of this type | Combat log showing all damage |
290
+ | `RegisterGameObjectBroadcast` | Monitor broadcasts from specific GameObject | Health bar for one enemy |
291
+ | `RegisterComponentBroadcast` | Monitor broadcasts from specific Component | Track specific weapon's fire events |
292
+
293
+ ---
294
+
295
+ ## Debugging Tips
296
+
297
+ ### Enable Diagnostics
298
+
299
+ 1. Select any GameObject with `MessagingComponent`
300
+ 1. In the Inspector, find the MessagingComponent
301
+ 1. Check the **"Enable Diagnostics"** box
302
+ 1. Press Play
303
+
304
+ #### What you'll see:
305
+
306
+ - Real-time log of messages sent and received
307
+ - Message types and payloads
308
+ - Source and target information
309
+ - Timing information
310
+
311
+ ### Debugging Checklist
312
+
313
+ #### Message not received?
314
+
315
+ - [ ] Is `MessagingComponent` attached to the GameObject?
316
+ - [ ] Did you call `MessagingComponent.Create(this)` to get a token?
317
+ - [ ] Is the handler method registered correctly?
318
+ - [ ] Does the message type match exactly?
319
+ - [ ] Is the targeting correct (Component vs GameObject vs Untargeted)?
320
+
321
+ ##### Message received by wrong object?
322
+
323
+ - [ ] Check if using Broadcast when you meant Targeted
324
+ - [ ] Verify Component vs GameObject targeting
325
+ - [ ] Check registration method (`RegisterComponent` vs `RegisterGameObject`)
326
+
327
+ ###### Message sent but nothing happens?
328
+
329
+ - [ ] Verify handler method signature matches
330
+ - [ ] Check if GameObject is active
331
+ - [ ] Ensure Component is enabled
332
+ - [ ] Look for exceptions in Console
333
+
334
+ ---
335
+
336
+ ## Common Patterns Explained
337
+
338
+ ### Pattern 1: The Observer (UIOverlay)
339
+
340
+ **What**: A component that listens to many events without being directly involved
341
+
342
+ **Use for**: UI, analytics, audio, logging
343
+
344
+ **Key characteristic**: Uses `RegisterBroadcastWithoutSource` to monitor everything
345
+
346
+ ### Pattern 2: The Direct Recipient (Player)
347
+
348
+ **What**: A component that receives targeted instructions
349
+
350
+ **Use for**: Entities receiving commands, objects being modified
351
+
352
+ **Key characteristic**: Uses `RegisterComponent` for precise delivery
353
+
354
+ ### Pattern 3: The Broadcaster (Enemy)
355
+
356
+ **What**: A component that announces events without knowing who's listening
357
+
358
+ **Use for**: Events that multiple systems care about
359
+
360
+ **Key characteristic**: Uses `EmitBroadcast` to send messages
361
+
362
+ ### Pattern 4: The Orchestrator (Boot)
363
+
364
+ **What**: A component that coordinates by sending multiple messages
365
+
366
+ **Use for**: Game flow, cutscenes, tutorials, state machines
367
+
368
+ **Key characteristic**: Publishes various message types to drive the system
369
+
370
+ ---
371
+
372
+ ## Key Takeaways
373
+
374
+ ### For Beginners
375
+
376
+ 1. **Messages replace direct references**: Instead of `player.Heal()`, use messages
377
+ 1. **Three targeting types**: Untargeted (everyone), Targeted (someone specific), Broadcast (anyone listening)
378
+ 1. **MessagingComponent is required**: It manages the lifecycle of your subscriptions
379
+ 1. **Diagnostics are your friend**: Always enable them when learning
380
+
381
+ ### For Intermediate Developers
382
+
383
+ 1. **Choose targeting carefully**: Match the message type to your use case
384
+ 1. **Broadcast doesn't mean inefficient**: DxMessaging is highly optimized
385
+ 1. **Tokens prevent memory leaks**: They auto-unregister when destroyed
386
+ 1. **Assembly definitions matter**: Configure them correctly for separate assemblies
387
+
388
+ ### For Advanced Developers
389
+
390
+ 1. **Source-filtered broadcasts exist**: Use `RegisterGameObjectBroadcast` for efficiency
391
+ 1. **Message order can be controlled**: See the Interceptors & Ordering documentation
392
+ 1. **Performance considerations**: Targeted > Broadcast in terms of overhead
393
+ 1. **Consider message granularity**: Too many message types = harder maintenance
394
+
395
+ ---
396
+
397
+ ## What's Next
398
+
399
+ ### Experiment and Extend
400
+
401
+ Try modifying the sample:
402
+
403
+ - Add a second Player and see targeted messages in action
404
+ - Create a `PlayerDied` broadcast and handle it in multiple places
405
+ - Add a UI button that sends messages when clicked
406
+ - Implement a damage-over-time system using messages
407
+
408
+ ### Learn More
409
+
410
+ - **[Message Types Documentation](../../docs/concepts/message-types.md)** - Complete message type reference
411
+ - **[Targeting and Context Guide](../../docs/concepts/targeting-and-context.md)** - How GameObject and Component targets resolve to InstanceIds
412
+ - **[Patterns Guide](../../docs/guides/patterns.md)** - Common messaging patterns
413
+ - **[Performance Guide](../../docs/architecture/performance.md)** - Optimization tips
414
+
415
+ ---
416
+
417
+ ## Quick Reference Card
418
+
419
+ | Want to... | Use... | Example |
420
+ |------------|--------|---------|
421
+ | Send to everyone | Untargeted | `var paused = new GamePaused(); paused.Emit();` |
422
+ | Send to specific Component | Targeted | `var heal = new Heal(10); heal.EmitComponentTargeted(playerComponent);` |
423
+ | Announce an event | Broadcast | `this.EmitBroadcast(new Exploded())` |
424
+ | Listen to everything | `RegisterBroadcastWithoutSource` | `token.RegisterBroadcastWithoutSource<Damage>(OnDamage)` |
425
+ | Listen to specific source | `RegisterComponentBroadcast` | `token.RegisterComponentBroadcast<Fire>(weapon, OnFire)` |
426
+ | Receive targeted messages | `RegisterComponentTargeted` | `token.RegisterComponentTargeted<Heal>(this, OnHeal)` |
427
+
428
+ ---
429
+
430
+ **Remember**: Keep Player, Enemy, and UIOverlay GameObjects each with a `MessagingComponent` attached, and enable diagnostics to observe message traffic.