com.wallstop-studios.dxmessaging 2.0.0 → 2.1.1
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.
- package/.github/workflows/format-on-demand.yml +2 -2
- package/.github/workflows/json-format-check.yml +1 -1
- package/.github/workflows/markdown-json.yml +1 -1
- package/.github/workflows/markdownlint.yml +1 -1
- package/.github/workflows/npm-publish.yml +1 -1
- package/.github/workflows/prettier-autofix.yml +2 -2
- package/.github/workflows/yaml-format-lint.yml +1 -1
- package/Docs/Advanced.md +26 -1
- package/Docs/Comparisons.md +1229 -146
- package/Docs/Compatibility.md +27 -0
- package/Docs/DesignAndArchitecture.md +41 -34
- package/Docs/EmitShorthands.md +34 -0
- package/Docs/Helpers.md +91 -76
- package/Docs/Index.md +28 -25
- package/Docs/Install.md +29 -6
- package/Docs/Integrations/Reflex.md +292 -0
- package/{package-lock.json.meta → Docs/Integrations/Reflex.md.meta} +1 -1
- package/Docs/Integrations/VContainer.md +324 -0
- package/Docs/Integrations/VContainer.md.meta +7 -0
- package/Docs/Integrations/Zenject.md +333 -0
- package/Docs/Integrations/Zenject.md.meta +7 -0
- package/{Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.pdb.meta → Docs/Integrations.meta} +2 -1
- package/Docs/InterceptorsAndOrdering.md +371 -17
- package/Docs/ListeningPatterns.md +206 -0
- package/Docs/MessageBusProviders.md +496 -0
- package/Docs/MessageBusProviders.md.meta +7 -0
- package/Docs/MessageTypes.md +27 -0
- package/Docs/MigrationGuide.md +45 -0
- package/Docs/Patterns.md +286 -0
- package/Docs/Performance.md +9 -9
- package/Docs/QuickReference.md +31 -0
- package/Docs/QuickStart.md +1 -2
- package/Docs/RuntimeConfiguration.md +407 -0
- package/Docs/RuntimeConfiguration.md.meta +7 -0
- package/Docs/UnityIntegration.md +3 -1
- package/Docs/VisualGuide.md +206 -157
- package/Editor/CustomEditors/MessagingComponentEditor.cs +15 -6
- package/README.md +148 -26
- package/Runtime/AssemblyInfo.cs +4 -0
- package/Runtime/Core/Attributes/DxAutoConstructorAttribute.cs +1 -1
- package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs +1 -1
- package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs +1 -1
- package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs +1 -1
- package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs +1 -1
- package/Runtime/Core/Extensions/MessageBusExtensions.cs +253 -0
- package/Runtime/Core/Extensions/MessageBusExtensions.cs.meta +12 -0
- package/Runtime/Core/Extensions/MessageExtensions.cs +137 -89
- package/Runtime/Core/MessageBus/GlobalMessageBusProvider.cs +23 -0
- package/Runtime/Core/MessageBus/GlobalMessageBusProvider.cs.meta +11 -0
- package/Runtime/Core/MessageBus/IMessageBusProvider.cs +14 -0
- package/Runtime/Core/MessageBus/IMessageBusProvider.cs.meta +11 -0
- package/Runtime/Core/MessageBus/IMessageRegistrationBuilder.cs +18 -0
- package/Runtime/Core/MessageBus/IMessageRegistrationBuilder.cs.meta +11 -0
- package/Runtime/Core/MessageBus/MessageBusRebindMode.cs +26 -0
- package/Runtime/Core/MessageBus/MessageBusRebindMode.cs.meta +11 -0
- package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs +383 -0
- package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs.meta +11 -0
- package/Runtime/Core/MessageHandler.cs +198 -27
- package/Runtime/Core/MessageRegistrationToken.cs +67 -25
- package/Runtime/Core/Messages/IBroadcastMessage.cs +1 -1
- package/Runtime/Core/Messages/ITargetedMessage.cs +1 -1
- package/Runtime/Core/Messages/IUntargetedMessage.cs +1 -1
- package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs +31 -0
- package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs.meta +12 -0
- package/Runtime/Unity/InitialGlobalMessageBusProvider.cs +38 -0
- package/Runtime/Unity/InitialGlobalMessageBusProvider.cs.meta +12 -0
- package/Runtime/Unity/Integrations/Reflex/AssemblyInfo.cs +11 -0
- package/Runtime/Unity/Integrations/Reflex/AssemblyInfo.cs.meta +3 -0
- package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs +73 -0
- package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs.meta +11 -0
- package/Runtime/Unity/Integrations/Reflex/WallstopStudios.DxMessaging.Reflex.asmdef +20 -0
- package/Runtime/Unity/Integrations/Reflex/WallstopStudios.DxMessaging.Reflex.asmdef.meta +7 -0
- package/Runtime/Unity/Integrations/Reflex.meta +8 -0
- package/Runtime/Unity/Integrations/VContainer/AssemblyInfo.cs +11 -0
- package/Runtime/Unity/Integrations/VContainer/AssemblyInfo.cs.meta +3 -0
- package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs +46 -0
- package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs.meta +11 -0
- package/Runtime/Unity/Integrations/VContainer/WallstopStudios.DxMessaging.VContainer.asmdef +30 -0
- package/Runtime/Unity/Integrations/VContainer/WallstopStudios.DxMessaging.VContainer.asmdef.meta +7 -0
- package/Runtime/Unity/Integrations/VContainer.meta +8 -0
- package/Runtime/Unity/Integrations/Zenject/AssemblyInfo.cs +11 -0
- package/Runtime/Unity/Integrations/Zenject/AssemblyInfo.cs.meta +3 -0
- package/Runtime/Unity/Integrations/Zenject/WallstopStudios.DxMessaging.Zenject.asmdef +30 -0
- package/Runtime/Unity/Integrations/Zenject/WallstopStudios.DxMessaging.Zenject.asmdef.meta +7 -0
- package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs +55 -0
- package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs.meta +11 -0
- package/Runtime/Unity/Integrations/Zenject.meta +8 -0
- package/Runtime/Unity/Integrations.meta +8 -0
- package/Runtime/Unity/MessageAwareComponent.cs +102 -0
- package/Runtime/Unity/MessageBusProviderHandle.cs +97 -0
- package/Runtime/Unity/MessageBusProviderHandle.cs.meta +12 -0
- package/Runtime/Unity/MessagingComponent.cs +175 -9
- package/Runtime/Unity/MessagingComponentInstaller.cs +120 -0
- package/Runtime/Unity/MessagingComponentInstaller.cs.meta +12 -0
- package/Runtime/Unity/ScriptableMessageBusProvider.cs +14 -0
- package/Runtime/Unity/ScriptableMessageBusProvider.cs.meta +12 -0
- package/Samples~/DI/Prefabs/MessagingInstallerSample.prefab +98 -0
- package/Samples~/DI/Prefabs/MessagingInstallerSample.prefab.meta +7 -0
- package/Samples~/DI/Prefabs.meta +8 -0
- package/Samples~/DI/Providers/GlobalMessageBusProvider.asset +14 -0
- package/Samples~/DI/Providers/GlobalMessageBusProvider.asset.meta +8 -0
- package/Samples~/DI/Providers/InitialGlobalMessageBusProvider.asset +14 -0
- package/Samples~/DI/Providers/InitialGlobalMessageBusProvider.asset.meta +8 -0
- package/Samples~/DI/Providers.meta +8 -0
- package/Samples~/DI/README.md +51 -0
- package/Samples~/DI/README.md.meta +7 -0
- package/Samples~/DI/Reflex/SampleInstaller.cs +75 -0
- package/Samples~/DI/Reflex/SampleInstaller.cs.meta +11 -0
- package/Samples~/DI/Reflex.meta +8 -0
- package/Samples~/DI/VContainer/SampleLifetimeScope.cs +79 -0
- package/Samples~/DI/VContainer/SampleLifetimeScope.cs.meta +11 -0
- package/Samples~/DI/VContainer.meta +8 -0
- package/Samples~/DI/Zenject/SampleInstaller.cs +65 -0
- package/Samples~/DI/Zenject/SampleInstaller.cs.meta +11 -0
- package/Samples~/DI/Zenject.meta +8 -0
- package/Samples~/DI.meta +8 -0
- package/Samples~/Mini Combat/README.md +5 -7
- package/Samples~/Mini Combat/Walkthrough.md +18 -24
- package/Samples~/UI Buttons + Inspector/DiagnosticsEnabler.cs +12 -2
- package/Samples~/UI Buttons + Inspector/README.md.meta +7 -0
- package/Tests/Runtime/Benchmarks/BenchmarkSession.cs +444 -0
- package/Tests/Runtime/Benchmarks/BenchmarkSession.cs.meta +11 -0
- package/Tests/Runtime/Benchmarks/BenchmarkTestBase.cs +94 -0
- package/Tests/Runtime/Benchmarks/BenchmarkTestBase.cs.meta +11 -0
- package/Tests/Runtime/Benchmarks/ComparisonPerformanceTests.cs +395 -0
- package/Tests/Runtime/Benchmarks/ComparisonPerformanceTests.cs.meta +11 -0
- package/Tests/Runtime/Benchmarks/PerformanceTests.cs +77 -429
- package/Tests/Runtime/Benchmarks/ProviderResolutionBenchmarks.cs +142 -0
- package/Tests/Runtime/Benchmarks/ProviderResolutionBenchmarks.cs.meta +12 -0
- package/Tests/Runtime/Benchmarks/WallstopStudios.DxMessaging.Tests.Runtime.Benchmarks.asmdef +50 -0
- package/Tests/Runtime/Benchmarks/WallstopStudios.DxMessaging.Tests.Runtime.Benchmarks.asmdef.meta +7 -0
- package/Tests/Runtime/Core/DefaultBusFallbackTests.cs +333 -0
- package/Tests/Runtime/Core/DefaultBusFallbackTests.cs.meta +11 -0
- package/Tests/Runtime/Core/Extensions/MessageBusExtensionsTests.cs +278 -0
- package/Tests/Runtime/Core/Extensions/MessageBusExtensionsTests.cs.meta +11 -0
- package/Tests/Runtime/Core/Extensions/MessageExtensionsProviderTests.cs +289 -0
- package/Tests/Runtime/Core/Extensions/MessageExtensionsProviderTests.cs.meta +11 -0
- package/Tests/Runtime/Core/Extensions.meta +8 -0
- package/Tests/Runtime/Core/IntegrationShimSmokeTests.cs +57 -0
- package/Tests/Runtime/Core/IntegrationShimSmokeTests.cs.meta +11 -0
- package/Tests/Runtime/Core/MessageHandlerGlobalBusTests.cs +219 -0
- package/Tests/Runtime/Core/MessageHandlerGlobalBusTests.cs.meta +11 -0
- package/Tests/Runtime/Core/MessageRegistrationBuilderTests.cs +204 -0
- package/Tests/Runtime/Core/MessageRegistrationBuilderTests.cs.meta +11 -0
- package/Tests/Runtime/Core/MessagingTestBase.cs +4 -4
- package/Tests/Runtime/Core/NominalTests.cs +2 -2
- package/Tests/Runtime/Core/TypedShorthandTests.cs +2 -2
- package/Tests/Runtime/Core/UntargetedEquivalenceTests.cs +1 -1
- package/Tests/Runtime/Core/UntargetedPrefreezeTests.cs +2 -4
- package/Tests/Runtime/Integrations/Reflex/ReflexIntegrationTests.cs +162 -0
- package/Tests/Runtime/Integrations/Reflex/ReflexIntegrationTests.cs.meta +11 -0
- package/Tests/Runtime/Integrations/Reflex/Resources/ReflexSettings.asset +16 -0
- package/Tests/Runtime/Integrations/Reflex/Resources/ReflexSettings.asset.meta +8 -0
- package/Tests/Runtime/Integrations/Reflex/Resources.meta +8 -0
- package/Tests/Runtime/Integrations/Reflex/WallstopStudios.DxMessaging.Tests.Runtime.Reflex.asmdef +27 -0
- package/Tests/Runtime/Integrations/Reflex/WallstopStudios.DxMessaging.Tests.Runtime.Reflex.asmdef.meta +7 -0
- package/Tests/Runtime/Integrations/Reflex.meta +8 -0
- package/Tests/Runtime/Integrations/VContainer/VContainerIntegrationTests.cs +140 -0
- package/Tests/Runtime/Integrations/VContainer/VContainerIntegrationTests.cs.meta +11 -0
- package/Tests/Runtime/Integrations/VContainer/WallstopStudios.DxMessaging.Tests.Runtime.VContainer.asmdef +37 -0
- package/Tests/Runtime/Integrations/VContainer/WallstopStudios.DxMessaging.Tests.Runtime.VContainer.asmdef.meta +7 -0
- package/Tests/Runtime/Integrations/VContainer.meta +8 -0
- package/Tests/Runtime/Integrations/Zenject/WallstopStudios.DxMessaging.Tests.Runtime.Zenject.asmdef +37 -0
- package/Tests/Runtime/Integrations/Zenject/WallstopStudios.DxMessaging.Tests.Runtime.Zenject.asmdef.meta +7 -0
- package/Tests/Runtime/Integrations/Zenject/ZenjectIntegrationTests.cs +140 -0
- package/Tests/Runtime/Integrations/Zenject/ZenjectIntegrationTests.cs.meta +11 -0
- package/Tests/Runtime/Integrations/Zenject.meta +8 -0
- package/Tests/Runtime/Integrations.meta +8 -0
- package/Tests/Runtime/Scripts/Components/EmptyMessageAwareComponent.cs +1 -1
- package/Tests/Runtime/Scripts/Components/GenericMessageAwareComponent.cs +1 -1
- package/Tests/Runtime/Scripts/Components/SimpleMessageAwareComponent.cs +1 -1
- package/Tests/Runtime/TestUtilities/UnityFixtureBase.cs +64 -0
- package/Tests/Runtime/TestUtilities/UnityFixtureBase.cs.meta +12 -0
- package/Tests/Runtime/TestUtilities.meta +9 -0
- package/Tests/Runtime/Unity/MessageBusProviderAssetTests.cs +57 -0
- package/Tests/Runtime/Unity/MessageBusProviderAssetTests.cs.meta +11 -0
- package/Tests/Runtime/Unity/MessageBusProviderHandleTests.cs +107 -0
- package/Tests/Runtime/Unity/MessageBusProviderHandleTests.cs.meta +12 -0
- package/Tests/Runtime/Unity/MessagingComponentProviderIntegrationTests.cs +210 -0
- package/Tests/Runtime/Unity/MessagingComponentProviderIntegrationTests.cs.meta +12 -0
- package/Tests/Runtime/Unity.meta +9 -0
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.asmdef +3 -1
- package/package.json +1 -1
package/Docs/VisualGuide.md
CHANGED
|
@@ -6,45 +6,67 @@ If you're brand new to messaging systems, this visual guide will help you unders
|
|
|
6
6
|
|
|
7
7
|
### The Old Way (Spaghetti Code)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
9
|
+
```mermaid
|
|
10
|
+
graph LR
|
|
11
|
+
Player[Player]
|
|
12
|
+
Enemy[Enemy]
|
|
13
|
+
Inventory[Inventory]
|
|
14
|
+
UI[UI]
|
|
15
|
+
Audio[Audio]
|
|
16
|
+
|
|
17
|
+
Player -->|direct ref| UI
|
|
18
|
+
Player -->|direct ref| Audio
|
|
19
|
+
Enemy -->|direct ref| UI
|
|
20
|
+
Enemy -->|direct ref| Audio
|
|
21
|
+
Inventory -->|direct ref| Audio
|
|
22
|
+
|
|
23
|
+
style Player fill:#ffa39e,stroke:#cf1322,stroke-width:2px,color:#000
|
|
24
|
+
style Enemy fill:#ffa39e,stroke:#cf1322,stroke-width:2px,color:#000
|
|
25
|
+
style Inventory fill:#ffa39e,stroke:#cf1322,stroke-width:2px,color:#000
|
|
26
|
+
style UI fill:#b7eb8f,stroke:#389e0d,stroke-width:2px,color:#000
|
|
27
|
+
style Audio fill:#b7eb8f,stroke:#389e0d,stroke-width:2px,color:#000
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
#### Problems
|
|
31
|
+
|
|
32
|
+
- ❌ Everyone needs to know everyone else
|
|
33
|
+
- ❌ Hard to add/remove systems
|
|
34
|
+
- ❌ Memory leaks from forgotten unsubscribes
|
|
27
35
|
|
|
28
36
|
### The DxMessaging Way (Clean Separation)
|
|
29
37
|
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
```mermaid
|
|
39
|
+
graph TB
|
|
40
|
+
Player[Player]
|
|
41
|
+
Enemy[Enemy]
|
|
42
|
+
Inventory[Inventory]
|
|
43
|
+
Bus((Message<br/>Bus))
|
|
44
|
+
UI[UI]
|
|
45
|
+
Audio[Audio]
|
|
46
|
+
Analytics[Analytics]
|
|
47
|
+
|
|
48
|
+
Player -->|message| Bus
|
|
49
|
+
Enemy -->|message| Bus
|
|
50
|
+
Inventory -->|message| Bus
|
|
51
|
+
|
|
52
|
+
Bus -->|notify| UI
|
|
53
|
+
Bus -->|notify| Audio
|
|
54
|
+
Bus -->|notify| Analytics
|
|
55
|
+
|
|
56
|
+
style Player fill:#91d5ff,stroke:#096dd9,stroke-width:2px,color:#000
|
|
57
|
+
style Enemy fill:#91d5ff,stroke:#096dd9,stroke-width:2px,color:#000
|
|
58
|
+
style Inventory fill:#91d5ff,stroke:#096dd9,stroke-width:2px,color:#000
|
|
59
|
+
style Bus fill:#ffd591,stroke:#d46b08,stroke-width:3px,color:#000
|
|
60
|
+
style UI fill:#95de64,stroke:#237804,stroke-width:2px,color:#000
|
|
61
|
+
style Audio fill:#95de64,stroke:#237804,stroke-width:2px,color:#000
|
|
62
|
+
style Analytics fill:#95de64,stroke:#237804,stroke-width:2px,color:#000
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### Benefits
|
|
66
|
+
|
|
67
|
+
- ✅ Nobody knows about anyone else
|
|
68
|
+
- ✅ Easy to add/remove systems
|
|
69
|
+
- ✅ Zero memory leaks (automatic cleanup)
|
|
48
70
|
|
|
49
71
|
## 📨 The Three Message Types (Simple!)
|
|
50
72
|
|
|
@@ -66,9 +88,9 @@ msg.Emit();
|
|
|
66
88
|
|
|
67
89
|
// Anyone can listen
|
|
68
90
|
_ = token.RegisterUntargeted<GamePaused>(OnPause);
|
|
69
|
-
```
|
|
91
|
+
```
|
|
70
92
|
|
|
71
|
-
#### Real-world uses
|
|
93
|
+
#### Real-world uses
|
|
72
94
|
|
|
73
95
|
- "Game paused!"
|
|
74
96
|
- "Settings changed!"
|
|
@@ -90,9 +112,9 @@ heal.EmitGameObjectTargeted(playerObject);
|
|
|
90
112
|
|
|
91
113
|
// Only the player listens
|
|
92
114
|
_ = token.RegisterComponentTargeted<Heal>(this, OnHeal);
|
|
93
|
-
```
|
|
115
|
+
```
|
|
94
116
|
|
|
95
|
-
#### Real-world uses
|
|
117
|
+
#### Real-world uses
|
|
96
118
|
|
|
97
119
|
- "Player, heal yourself!"
|
|
98
120
|
- "Enemy #3, take damage!"
|
|
@@ -117,9 +139,9 @@ _ = token.RegisterGameObjectBroadcast<TookDamage>(enemyObject, OnThisEnemy);
|
|
|
117
139
|
|
|
118
140
|
// OR achievement system can listen to ALL enemies
|
|
119
141
|
_ = token.RegisterBroadcastWithoutSource<TookDamage>(OnAnyEnemy);
|
|
120
|
-
```
|
|
142
|
+
```
|
|
121
143
|
|
|
122
|
-
#### Real-world uses
|
|
144
|
+
#### Real-world uses
|
|
123
145
|
|
|
124
146
|
- "I (player) took damage!"
|
|
125
147
|
- "I (enemy) died!"
|
|
@@ -129,33 +151,49 @@ _ = token.RegisterBroadcastWithoutSource<TookDamage>(OnAnyEnemy);
|
|
|
129
151
|
|
|
130
152
|
When you send a message, here's what happens:
|
|
131
153
|
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
154
|
+
```mermaid
|
|
155
|
+
sequenceDiagram
|
|
156
|
+
participant You as Your Code
|
|
157
|
+
participant Msg as Message
|
|
158
|
+
participant Int as Interceptors<br/>(Optional)
|
|
159
|
+
participant H0 as Handler<br/>priority: 0
|
|
160
|
+
participant H5 as Handler<br/>priority: 5
|
|
161
|
+
participant H10 as Handler<br/>priority: 10
|
|
162
|
+
participant PP as Post-Processors<br/>(Optional)
|
|
163
|
+
|
|
164
|
+
Note over You: 1. Create message
|
|
165
|
+
You->>Msg: var heal = new Heal(10);
|
|
166
|
+
|
|
167
|
+
Note over You,Msg: 2. Emit message
|
|
168
|
+
You->>Msg: heal.EmitGameObjectTargeted(player);
|
|
169
|
+
|
|
170
|
+
Note over Int: 3. Validate & Normalize
|
|
171
|
+
Msg->>Int: Check message
|
|
172
|
+
Int->>Int: Is valid? (>0)<br/>Clamp if needed (<999)
|
|
173
|
+
alt Invalid message
|
|
174
|
+
Int--xMsg: ❌ Cancel
|
|
175
|
+
else Valid message
|
|
176
|
+
Int->>H0: ✅ Continue
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
Note over H0,H10: 4. Execute handlers (by priority)
|
|
180
|
+
H0->>H0: SaveSystem runs first
|
|
181
|
+
H0->>H5: Next priority
|
|
182
|
+
H5->>H5: AudioSystem runs
|
|
183
|
+
H5->>H10: Next priority
|
|
184
|
+
H10->>H10: UISystem runs last
|
|
185
|
+
|
|
186
|
+
Note over PP: 5. Analytics & Logging
|
|
187
|
+
H10->>PP: All handlers complete
|
|
188
|
+
PP->>PP: Analytics.Track(...)<br/>Debug.Log(...)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Key points
|
|
192
|
+
|
|
193
|
+
- **Step 1-2:** You create and emit the message
|
|
194
|
+
- **Step 3 (Optional):** Interceptors can validate, modify, or cancel
|
|
195
|
+
- **Step 4:** Handlers run in priority order (lower number = earlier)
|
|
196
|
+
- **Step 5 (Optional):** Post-processors run after everything (perfect for analytics)
|
|
159
197
|
|
|
160
198
|
## 🎮 Your First Message (3 Easy Steps)
|
|
161
199
|
|
|
@@ -169,7 +207,7 @@ using DxMessaging.Core.Attributes;
|
|
|
169
207
|
public readonly partial struct Heal {
|
|
170
208
|
public readonly int amount;
|
|
171
209
|
}
|
|
172
|
-
|
|
210
|
+
```
|
|
173
211
|
|
|
174
212
|
#### What are those `[DxSomething]` tags?
|
|
175
213
|
|
|
@@ -228,20 +266,29 @@ healMsg.EmitComponentTargeted(playerComponent);
|
|
|
228
266
|
|
|
229
267
|
### Pattern: Scene Transition
|
|
230
268
|
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
269
|
+
```mermaid
|
|
270
|
+
sequenceDiagram
|
|
271
|
+
participant SM as SceneManager
|
|
272
|
+
participant Bus as Message Bus
|
|
273
|
+
participant Audio as AudioSystem
|
|
274
|
+
participant Save as SaveSystem
|
|
275
|
+
|
|
276
|
+
Note over SM: Scene is changing
|
|
277
|
+
SM->>Bus: SceneChanged(sceneIndex: 2)
|
|
278
|
+
|
|
279
|
+
Note over Bus: Message broadcast to all listeners
|
|
280
|
+
|
|
281
|
+
Bus->>Audio: SceneChanged received
|
|
282
|
+
Audio->>Audio: FadeOutMusic()
|
|
283
|
+
|
|
284
|
+
Bus->>Save: SceneChanged received
|
|
285
|
+
Save->>Save: SaveGame()
|
|
286
|
+
|
|
287
|
+
Note over Audio,Save: ✅ All independent!<br/>No coupling!
|
|
243
288
|
```
|
|
244
289
|
|
|
290
|
+
**Why this works:** AudioSystem and SaveSystem don't know about SceneManager or each other. They just listen for `SceneChanged` messages and react independently.
|
|
291
|
+
|
|
245
292
|
Code:
|
|
246
293
|
|
|
247
294
|
```csharp
|
|
@@ -261,16 +308,23 @@ _ = saveToken.RegisterUntargeted<SceneChanged>(OnScene);
|
|
|
261
308
|
|
|
262
309
|
### Pattern: Player Input → Action
|
|
263
310
|
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
311
|
+
```mermaid
|
|
312
|
+
sequenceDiagram
|
|
313
|
+
participant Input as InputSystem
|
|
314
|
+
participant Bus as Message Bus
|
|
315
|
+
participant Player as Player
|
|
316
|
+
|
|
317
|
+
Note over Input: User presses Space
|
|
318
|
+
Input->>Bus: Jump(force: 10f)<br/>[Targeted to Player]
|
|
319
|
+
|
|
320
|
+
Bus->>Player: Jump message received
|
|
321
|
+
Player->>Player: ApplyForce()<br/>rb.AddForce(...)
|
|
270
322
|
|
|
271
|
-
|
|
323
|
+
Note over Input,Player: ✅ Decoupled!<br/>Input doesn't reference Player
|
|
272
324
|
```
|
|
273
325
|
|
|
326
|
+
**Why this works:** InputSystem doesn't need a reference to Player. It just sends a `Jump` message targeted at the player, and the player responds.
|
|
327
|
+
|
|
274
328
|
Code:
|
|
275
329
|
|
|
276
330
|
```csharp
|
|
@@ -291,15 +345,29 @@ void OnJump(ref Jump msg) {
|
|
|
291
345
|
|
|
292
346
|
### Pattern: Achievement Tracking
|
|
293
347
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
348
|
+
```mermaid
|
|
349
|
+
sequenceDiagram
|
|
350
|
+
participant E as Enemy
|
|
351
|
+
participant P as Player
|
|
352
|
+
participant C as Chest
|
|
353
|
+
participant Bus as Message Bus
|
|
354
|
+
participant Ach as Achievement System
|
|
355
|
+
|
|
356
|
+
Note over Ach: Listens to ALL messages
|
|
300
357
|
|
|
301
|
-
|
|
302
|
-
|
|
358
|
+
E->>Bus: EnemyKilled
|
|
359
|
+
Bus->>Ach: CheckProgress()<br/>UnlockIfReady()
|
|
360
|
+
|
|
361
|
+
P->>Bus: LevelCompleted
|
|
362
|
+
Bus->>Ach: CheckProgress()<br/>UnlockIfReady()
|
|
363
|
+
|
|
364
|
+
C->>Bus: ChestOpened
|
|
365
|
+
Bus->>Ach: CheckProgress()<br/>UnlockIfReady()
|
|
366
|
+
|
|
367
|
+
Note over Ach: ✅ Sees EVERYTHING<br/>without coupling!
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
**Why this works:** Achievement System uses `RegisterGlobalAcceptAll()` to observe every message type, tracking progress across the entire game without any system knowing about it.
|
|
303
371
|
|
|
304
372
|
Code:
|
|
305
373
|
|
|
@@ -315,7 +383,7 @@ public class AchievementSystem : MessageAwareComponent {
|
|
|
315
383
|
);
|
|
316
384
|
}
|
|
317
385
|
}
|
|
318
|
-
|
|
386
|
+
```
|
|
319
387
|
|
|
320
388
|
## 🚦 When to Use Which Message Type
|
|
321
389
|
|
|
@@ -344,64 +412,51 @@ Think of DxMessaging like a restaurant:
|
|
|
344
412
|
|
|
345
413
|
### Untargeted = Restaurant Announcement
|
|
346
414
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
→ Everyone hears it
|
|
350
|
-
```text
|
|
415
|
+
> "Attention all customers: We're closing in 10 minutes!"
|
|
416
|
+
>
|
|
417
|
+
> → Everyone hears it
|
|
351
418
|
|
|
352
419
|
### Targeted = Waiter Delivering Food
|
|
353
420
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
→ Only table 5 gets it
|
|
357
|
-
````
|
|
421
|
+
> "Order for table 5: Here's your burger"
|
|
422
|
+
>
|
|
423
|
+
> → Only table 5 gets it
|
|
358
424
|
|
|
359
425
|
### Broadcast = Customer Calling Waiter
|
|
360
426
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
→ Comes from table 3
|
|
364
|
-
|
|
365
|
-
→
|
|
366
|
-
|
|
427
|
+
> "Excuse me, I need a refill!" (from table 3)
|
|
428
|
+
>
|
|
429
|
+
> → Comes from table 3
|
|
430
|
+
>
|
|
431
|
+
> → Any available waiter can respond
|
|
432
|
+
>
|
|
433
|
+
> → Manager might track it for statistics
|
|
367
434
|
|
|
368
435
|
## 🔍 Debugging Visualized
|
|
369
436
|
|
|
370
437
|
DxMessaging has built-in Inspector support!
|
|
371
438
|
|
|
372
|
-
|
|
373
|
-
MessagingComponent Inspector:
|
|
374
|
-
┌─────────────────────────────────────┐
|
|
375
|
-
│ Message History (last 10) │
|
|
376
|
-
│ ┌─────────────────────────────────┐ │
|
|
377
|
-
│ │ 12:34:05 - Heal → Player (50) │ │
|
|
378
|
-
│ │ 12:34:03 - Jump → Player │ │
|
|
379
|
-
│ │ 12:34:01 - GamePaused (global) │ │
|
|
380
|
-
│ └─────────────────────────────────┘ │
|
|
381
|
-
│ │
|
|
382
|
-
│ Registrations: │
|
|
383
|
-
│ ┌─────────────────────────────────┐ │
|
|
384
|
-
│ │ ✓ Heal (priority: 0, 5 calls) │ │
|
|
385
|
-
│ │ ✓ Jump (priority: 0, 2 calls) │ │
|
|
386
|
-
│ │ ✓ TookDamage (priority: 10) │ │
|
|
387
|
-
│ └─────────────────────────────────┘ │
|
|
388
|
-
└─────────────────────────────────────┘
|
|
389
|
-
````
|
|
439
|
+
### MessagingComponent Inspector
|
|
390
440
|
|
|
391
|
-
|
|
441
|
+
#### Message History (last 10)
|
|
392
442
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
443
|
+
- `12:34:05 - Heal → Player (50)`
|
|
444
|
+
- `12:34:03 - Jump → Player`
|
|
445
|
+
- `12:34:01 - GamePaused (global)`
|
|
396
446
|
|
|
397
|
-
|
|
398
|
-
Traditional Events: ████████░░ (can leak!)
|
|
399
|
-
DxMessaging: ██░░░░░░░░ (zero leaks, struct messages)
|
|
447
|
+
##### Registrations
|
|
400
448
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
449
|
+
- ✓ Heal (priority: 0, 5 calls)
|
|
450
|
+
- ✓ Jump (priority: 0, 2 calls)
|
|
451
|
+
- ✓ TookDamage (priority: 10)
|
|
452
|
+
|
|
453
|
+
## ⚡ Performance at a Glance
|
|
454
|
+
|
|
455
|
+
| Metric | Traditional C# Events | DxMessaging |
|
|
456
|
+
| ------------ | --------------------- | ----------------------------------- |
|
|
457
|
+
| **Speed** | ⚡⚡⚡⚡ (baseline) | ⚡⚡⚡⚡ (~10ns slower, negligible) |
|
|
458
|
+
| **Memory** | ⚠️ Can leak! | ✅ Zero leaks (struct messages) |
|
|
459
|
+
| **Coupling** | ❌ Tight coupling | ✅ Zero coupling |
|
|
405
460
|
|
|
406
461
|
**Bottom line:** Slightly slower than raw events, but:
|
|
407
462
|
|
|
@@ -412,22 +467,16 @@ DxMessaging: ░░░░░░░░░░ (zero!)
|
|
|
412
467
|
|
|
413
468
|
## 🎓 Learning Path
|
|
414
469
|
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
│
|
|
426
|
-
├─→ 4. Read Common Patterns (15 min)
|
|
427
|
-
│ [Real-world solutions]
|
|
428
|
-
│
|
|
429
|
-
└─→ 5. Build your first feature! (30 min)
|
|
430
|
-
[You're ready!]
|
|
470
|
+
```mermaid
|
|
471
|
+
graph TD
|
|
472
|
+
Start[START HERE<br/>Read this Visual Guide<br/>5 min ✓]
|
|
473
|
+
Start --> Step2[Try Quick Start example<br/>5 min<br/>Define → Listen → Send]
|
|
474
|
+
Step2 --> Step3[Import Mini Combat sample<br/>10 min<br/>See it in action!]
|
|
475
|
+
Step3 --> Step4[Read Common Patterns<br/>15 min<br/>Real-world solutions]
|
|
476
|
+
Step4 --> Step5[Build your first feature!<br/>30 min<br/>You're ready!]
|
|
477
|
+
|
|
478
|
+
style Start fill:#91d5ff,stroke:#096dd9,stroke-width:3px,color:#000
|
|
479
|
+
style Step5 fill:#95de64,stroke:#237804,stroke-width:2px,color:#000
|
|
431
480
|
```
|
|
432
481
|
|
|
433
482
|
## 🆘 Common Beginner Questions
|
|
@@ -5,6 +5,7 @@ namespace DxMessaging.Editor.CustomEditors
|
|
|
5
5
|
using System.Linq;
|
|
6
6
|
using Core;
|
|
7
7
|
using Core.Diagnostics;
|
|
8
|
+
using Core.MessageBus;
|
|
8
9
|
using Core.Messages;
|
|
9
10
|
using Unity;
|
|
10
11
|
using UnityEditor;
|
|
@@ -107,18 +108,26 @@ namespace DxMessaging.Editor.CustomEditors
|
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
|
|
111
|
+
IMessageBus globalBus = MessageHandler.MessageBus;
|
|
112
|
+
if (globalBus is not MessageBus concreteBus)
|
|
113
|
+
{
|
|
114
|
+
EditorGUILayout.HelpBox(
|
|
115
|
+
"Global diagnostics controls are unavailable because the active global bus is not the default DxMessaging MessageBus implementation.",
|
|
116
|
+
MessageType.Info
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
else if (!concreteBus.DiagnosticsMode)
|
|
111
120
|
{
|
|
112
121
|
if (GUILayout.Button("Enable Global Diagnostics"))
|
|
113
122
|
{
|
|
114
|
-
|
|
123
|
+
concreteBus.DiagnosticsMode = true;
|
|
115
124
|
}
|
|
116
125
|
}
|
|
117
126
|
else
|
|
118
127
|
{
|
|
119
128
|
if (GUILayout.Button("Disable Global Diagnostics"))
|
|
120
129
|
{
|
|
121
|
-
|
|
130
|
+
concreteBus.DiagnosticsMode = false;
|
|
122
131
|
}
|
|
123
132
|
else
|
|
124
133
|
{
|
|
@@ -130,7 +139,7 @@ namespace DxMessaging.Editor.CustomEditors
|
|
|
130
139
|
"Global Messages",
|
|
131
140
|
true
|
|
132
141
|
);
|
|
133
|
-
int totalGlobalMessages =
|
|
142
|
+
int totalGlobalMessages = concreteBus._emissionBuffer.Count;
|
|
134
143
|
if (_globalBufferExpanded && totalGlobalMessages > 0)
|
|
135
144
|
{
|
|
136
145
|
int page = _globalBufferPaging;
|
|
@@ -163,8 +172,8 @@ namespace DxMessaging.Editor.CustomEditors
|
|
|
163
172
|
}
|
|
164
173
|
}
|
|
165
174
|
|
|
166
|
-
MessageEmissionData[] pagedGlobalMessages =
|
|
167
|
-
.
|
|
175
|
+
MessageEmissionData[] pagedGlobalMessages = concreteBus
|
|
176
|
+
._emissionBuffer.Reverse()
|
|
168
177
|
.Skip(page * PageSize)
|
|
169
178
|
.Take(PageSize)
|
|
170
179
|
.ToArray();
|