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.
Files changed (183) hide show
  1. package/.github/workflows/format-on-demand.yml +2 -2
  2. package/.github/workflows/json-format-check.yml +1 -1
  3. package/.github/workflows/markdown-json.yml +1 -1
  4. package/.github/workflows/markdownlint.yml +1 -1
  5. package/.github/workflows/npm-publish.yml +1 -1
  6. package/.github/workflows/prettier-autofix.yml +2 -2
  7. package/.github/workflows/yaml-format-lint.yml +1 -1
  8. package/Docs/Advanced.md +26 -1
  9. package/Docs/Comparisons.md +1229 -146
  10. package/Docs/Compatibility.md +27 -0
  11. package/Docs/DesignAndArchitecture.md +41 -34
  12. package/Docs/EmitShorthands.md +34 -0
  13. package/Docs/Helpers.md +91 -76
  14. package/Docs/Index.md +28 -25
  15. package/Docs/Install.md +29 -6
  16. package/Docs/Integrations/Reflex.md +292 -0
  17. package/{package-lock.json.meta → Docs/Integrations/Reflex.md.meta} +1 -1
  18. package/Docs/Integrations/VContainer.md +324 -0
  19. package/Docs/Integrations/VContainer.md.meta +7 -0
  20. package/Docs/Integrations/Zenject.md +333 -0
  21. package/Docs/Integrations/Zenject.md.meta +7 -0
  22. package/{Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.pdb.meta → Docs/Integrations.meta} +2 -1
  23. package/Docs/InterceptorsAndOrdering.md +371 -17
  24. package/Docs/ListeningPatterns.md +206 -0
  25. package/Docs/MessageBusProviders.md +496 -0
  26. package/Docs/MessageBusProviders.md.meta +7 -0
  27. package/Docs/MessageTypes.md +27 -0
  28. package/Docs/MigrationGuide.md +45 -0
  29. package/Docs/Patterns.md +286 -0
  30. package/Docs/Performance.md +9 -9
  31. package/Docs/QuickReference.md +31 -0
  32. package/Docs/QuickStart.md +1 -2
  33. package/Docs/RuntimeConfiguration.md +407 -0
  34. package/Docs/RuntimeConfiguration.md.meta +7 -0
  35. package/Docs/UnityIntegration.md +3 -1
  36. package/Docs/VisualGuide.md +206 -157
  37. package/Editor/CustomEditors/MessagingComponentEditor.cs +15 -6
  38. package/README.md +148 -26
  39. package/Runtime/AssemblyInfo.cs +4 -0
  40. package/Runtime/Core/Attributes/DxAutoConstructorAttribute.cs +1 -1
  41. package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs +1 -1
  42. package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs +1 -1
  43. package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs +1 -1
  44. package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs +1 -1
  45. package/Runtime/Core/Extensions/MessageBusExtensions.cs +253 -0
  46. package/Runtime/Core/Extensions/MessageBusExtensions.cs.meta +12 -0
  47. package/Runtime/Core/Extensions/MessageExtensions.cs +137 -89
  48. package/Runtime/Core/MessageBus/GlobalMessageBusProvider.cs +23 -0
  49. package/Runtime/Core/MessageBus/GlobalMessageBusProvider.cs.meta +11 -0
  50. package/Runtime/Core/MessageBus/IMessageBusProvider.cs +14 -0
  51. package/Runtime/Core/MessageBus/IMessageBusProvider.cs.meta +11 -0
  52. package/Runtime/Core/MessageBus/IMessageRegistrationBuilder.cs +18 -0
  53. package/Runtime/Core/MessageBus/IMessageRegistrationBuilder.cs.meta +11 -0
  54. package/Runtime/Core/MessageBus/MessageBusRebindMode.cs +26 -0
  55. package/Runtime/Core/MessageBus/MessageBusRebindMode.cs.meta +11 -0
  56. package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs +383 -0
  57. package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs.meta +11 -0
  58. package/Runtime/Core/MessageHandler.cs +198 -27
  59. package/Runtime/Core/MessageRegistrationToken.cs +67 -25
  60. package/Runtime/Core/Messages/IBroadcastMessage.cs +1 -1
  61. package/Runtime/Core/Messages/ITargetedMessage.cs +1 -1
  62. package/Runtime/Core/Messages/IUntargetedMessage.cs +1 -1
  63. package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs +31 -0
  64. package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs.meta +12 -0
  65. package/Runtime/Unity/InitialGlobalMessageBusProvider.cs +38 -0
  66. package/Runtime/Unity/InitialGlobalMessageBusProvider.cs.meta +12 -0
  67. package/Runtime/Unity/Integrations/Reflex/AssemblyInfo.cs +11 -0
  68. package/Runtime/Unity/Integrations/Reflex/AssemblyInfo.cs.meta +3 -0
  69. package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs +73 -0
  70. package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs.meta +11 -0
  71. package/Runtime/Unity/Integrations/Reflex/WallstopStudios.DxMessaging.Reflex.asmdef +20 -0
  72. package/Runtime/Unity/Integrations/Reflex/WallstopStudios.DxMessaging.Reflex.asmdef.meta +7 -0
  73. package/Runtime/Unity/Integrations/Reflex.meta +8 -0
  74. package/Runtime/Unity/Integrations/VContainer/AssemblyInfo.cs +11 -0
  75. package/Runtime/Unity/Integrations/VContainer/AssemblyInfo.cs.meta +3 -0
  76. package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs +46 -0
  77. package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs.meta +11 -0
  78. package/Runtime/Unity/Integrations/VContainer/WallstopStudios.DxMessaging.VContainer.asmdef +30 -0
  79. package/Runtime/Unity/Integrations/VContainer/WallstopStudios.DxMessaging.VContainer.asmdef.meta +7 -0
  80. package/Runtime/Unity/Integrations/VContainer.meta +8 -0
  81. package/Runtime/Unity/Integrations/Zenject/AssemblyInfo.cs +11 -0
  82. package/Runtime/Unity/Integrations/Zenject/AssemblyInfo.cs.meta +3 -0
  83. package/Runtime/Unity/Integrations/Zenject/WallstopStudios.DxMessaging.Zenject.asmdef +30 -0
  84. package/Runtime/Unity/Integrations/Zenject/WallstopStudios.DxMessaging.Zenject.asmdef.meta +7 -0
  85. package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs +55 -0
  86. package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs.meta +11 -0
  87. package/Runtime/Unity/Integrations/Zenject.meta +8 -0
  88. package/Runtime/Unity/Integrations.meta +8 -0
  89. package/Runtime/Unity/MessageAwareComponent.cs +102 -0
  90. package/Runtime/Unity/MessageBusProviderHandle.cs +97 -0
  91. package/Runtime/Unity/MessageBusProviderHandle.cs.meta +12 -0
  92. package/Runtime/Unity/MessagingComponent.cs +175 -9
  93. package/Runtime/Unity/MessagingComponentInstaller.cs +120 -0
  94. package/Runtime/Unity/MessagingComponentInstaller.cs.meta +12 -0
  95. package/Runtime/Unity/ScriptableMessageBusProvider.cs +14 -0
  96. package/Runtime/Unity/ScriptableMessageBusProvider.cs.meta +12 -0
  97. package/Samples~/DI/Prefabs/MessagingInstallerSample.prefab +98 -0
  98. package/Samples~/DI/Prefabs/MessagingInstallerSample.prefab.meta +7 -0
  99. package/Samples~/DI/Prefabs.meta +8 -0
  100. package/Samples~/DI/Providers/GlobalMessageBusProvider.asset +14 -0
  101. package/Samples~/DI/Providers/GlobalMessageBusProvider.asset.meta +8 -0
  102. package/Samples~/DI/Providers/InitialGlobalMessageBusProvider.asset +14 -0
  103. package/Samples~/DI/Providers/InitialGlobalMessageBusProvider.asset.meta +8 -0
  104. package/Samples~/DI/Providers.meta +8 -0
  105. package/Samples~/DI/README.md +51 -0
  106. package/Samples~/DI/README.md.meta +7 -0
  107. package/Samples~/DI/Reflex/SampleInstaller.cs +75 -0
  108. package/Samples~/DI/Reflex/SampleInstaller.cs.meta +11 -0
  109. package/Samples~/DI/Reflex.meta +8 -0
  110. package/Samples~/DI/VContainer/SampleLifetimeScope.cs +79 -0
  111. package/Samples~/DI/VContainer/SampleLifetimeScope.cs.meta +11 -0
  112. package/Samples~/DI/VContainer.meta +8 -0
  113. package/Samples~/DI/Zenject/SampleInstaller.cs +65 -0
  114. package/Samples~/DI/Zenject/SampleInstaller.cs.meta +11 -0
  115. package/Samples~/DI/Zenject.meta +8 -0
  116. package/Samples~/DI.meta +8 -0
  117. package/Samples~/Mini Combat/README.md +5 -7
  118. package/Samples~/Mini Combat/Walkthrough.md +18 -24
  119. package/Samples~/UI Buttons + Inspector/DiagnosticsEnabler.cs +12 -2
  120. package/Samples~/UI Buttons + Inspector/README.md.meta +7 -0
  121. package/Tests/Runtime/Benchmarks/BenchmarkSession.cs +444 -0
  122. package/Tests/Runtime/Benchmarks/BenchmarkSession.cs.meta +11 -0
  123. package/Tests/Runtime/Benchmarks/BenchmarkTestBase.cs +94 -0
  124. package/Tests/Runtime/Benchmarks/BenchmarkTestBase.cs.meta +11 -0
  125. package/Tests/Runtime/Benchmarks/ComparisonPerformanceTests.cs +395 -0
  126. package/Tests/Runtime/Benchmarks/ComparisonPerformanceTests.cs.meta +11 -0
  127. package/Tests/Runtime/Benchmarks/PerformanceTests.cs +77 -429
  128. package/Tests/Runtime/Benchmarks/ProviderResolutionBenchmarks.cs +142 -0
  129. package/Tests/Runtime/Benchmarks/ProviderResolutionBenchmarks.cs.meta +12 -0
  130. package/Tests/Runtime/Benchmarks/WallstopStudios.DxMessaging.Tests.Runtime.Benchmarks.asmdef +50 -0
  131. package/Tests/Runtime/Benchmarks/WallstopStudios.DxMessaging.Tests.Runtime.Benchmarks.asmdef.meta +7 -0
  132. package/Tests/Runtime/Core/DefaultBusFallbackTests.cs +333 -0
  133. package/Tests/Runtime/Core/DefaultBusFallbackTests.cs.meta +11 -0
  134. package/Tests/Runtime/Core/Extensions/MessageBusExtensionsTests.cs +278 -0
  135. package/Tests/Runtime/Core/Extensions/MessageBusExtensionsTests.cs.meta +11 -0
  136. package/Tests/Runtime/Core/Extensions/MessageExtensionsProviderTests.cs +289 -0
  137. package/Tests/Runtime/Core/Extensions/MessageExtensionsProviderTests.cs.meta +11 -0
  138. package/Tests/Runtime/Core/Extensions.meta +8 -0
  139. package/Tests/Runtime/Core/IntegrationShimSmokeTests.cs +57 -0
  140. package/Tests/Runtime/Core/IntegrationShimSmokeTests.cs.meta +11 -0
  141. package/Tests/Runtime/Core/MessageHandlerGlobalBusTests.cs +219 -0
  142. package/Tests/Runtime/Core/MessageHandlerGlobalBusTests.cs.meta +11 -0
  143. package/Tests/Runtime/Core/MessageRegistrationBuilderTests.cs +204 -0
  144. package/Tests/Runtime/Core/MessageRegistrationBuilderTests.cs.meta +11 -0
  145. package/Tests/Runtime/Core/MessagingTestBase.cs +4 -4
  146. package/Tests/Runtime/Core/NominalTests.cs +2 -2
  147. package/Tests/Runtime/Core/TypedShorthandTests.cs +2 -2
  148. package/Tests/Runtime/Core/UntargetedEquivalenceTests.cs +1 -1
  149. package/Tests/Runtime/Core/UntargetedPrefreezeTests.cs +2 -4
  150. package/Tests/Runtime/Integrations/Reflex/ReflexIntegrationTests.cs +162 -0
  151. package/Tests/Runtime/Integrations/Reflex/ReflexIntegrationTests.cs.meta +11 -0
  152. package/Tests/Runtime/Integrations/Reflex/Resources/ReflexSettings.asset +16 -0
  153. package/Tests/Runtime/Integrations/Reflex/Resources/ReflexSettings.asset.meta +8 -0
  154. package/Tests/Runtime/Integrations/Reflex/Resources.meta +8 -0
  155. package/Tests/Runtime/Integrations/Reflex/WallstopStudios.DxMessaging.Tests.Runtime.Reflex.asmdef +27 -0
  156. package/Tests/Runtime/Integrations/Reflex/WallstopStudios.DxMessaging.Tests.Runtime.Reflex.asmdef.meta +7 -0
  157. package/Tests/Runtime/Integrations/Reflex.meta +8 -0
  158. package/Tests/Runtime/Integrations/VContainer/VContainerIntegrationTests.cs +140 -0
  159. package/Tests/Runtime/Integrations/VContainer/VContainerIntegrationTests.cs.meta +11 -0
  160. package/Tests/Runtime/Integrations/VContainer/WallstopStudios.DxMessaging.Tests.Runtime.VContainer.asmdef +37 -0
  161. package/Tests/Runtime/Integrations/VContainer/WallstopStudios.DxMessaging.Tests.Runtime.VContainer.asmdef.meta +7 -0
  162. package/Tests/Runtime/Integrations/VContainer.meta +8 -0
  163. package/Tests/Runtime/Integrations/Zenject/WallstopStudios.DxMessaging.Tests.Runtime.Zenject.asmdef +37 -0
  164. package/Tests/Runtime/Integrations/Zenject/WallstopStudios.DxMessaging.Tests.Runtime.Zenject.asmdef.meta +7 -0
  165. package/Tests/Runtime/Integrations/Zenject/ZenjectIntegrationTests.cs +140 -0
  166. package/Tests/Runtime/Integrations/Zenject/ZenjectIntegrationTests.cs.meta +11 -0
  167. package/Tests/Runtime/Integrations/Zenject.meta +8 -0
  168. package/Tests/Runtime/Integrations.meta +8 -0
  169. package/Tests/Runtime/Scripts/Components/EmptyMessageAwareComponent.cs +1 -1
  170. package/Tests/Runtime/Scripts/Components/GenericMessageAwareComponent.cs +1 -1
  171. package/Tests/Runtime/Scripts/Components/SimpleMessageAwareComponent.cs +1 -1
  172. package/Tests/Runtime/TestUtilities/UnityFixtureBase.cs +64 -0
  173. package/Tests/Runtime/TestUtilities/UnityFixtureBase.cs.meta +12 -0
  174. package/Tests/Runtime/TestUtilities.meta +9 -0
  175. package/Tests/Runtime/Unity/MessageBusProviderAssetTests.cs +57 -0
  176. package/Tests/Runtime/Unity/MessageBusProviderAssetTests.cs.meta +11 -0
  177. package/Tests/Runtime/Unity/MessageBusProviderHandleTests.cs +107 -0
  178. package/Tests/Runtime/Unity/MessageBusProviderHandleTests.cs.meta +12 -0
  179. package/Tests/Runtime/Unity/MessagingComponentProviderIntegrationTests.cs +210 -0
  180. package/Tests/Runtime/Unity/MessagingComponentProviderIntegrationTests.cs.meta +12 -0
  181. package/Tests/Runtime/Unity.meta +9 -0
  182. package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.asmdef +3 -1
  183. package/package.json +1 -1
@@ -0,0 +1,395 @@
1
+ namespace DxMessaging.Tests.Runtime.Benchmarks
2
+ {
3
+ using System;
4
+ using System.Diagnostics;
5
+ using DxMessaging.Core;
6
+ using DxMessaging.Core.Extensions;
7
+ using NUnit.Framework;
8
+ using Scripts.Messages;
9
+ using UnityEngine.TestTools.Constraints;
10
+ using Debug = UnityEngine.Debug;
11
+ using Is = NUnit.Framework.Is;
12
+ #if UNIRX_PRESENT
13
+ using UniRx;
14
+ #endif
15
+ #if MESSAGEPIPE_PRESENT
16
+ using MessagePipe;
17
+ #endif
18
+ #if ZENJECT_PRESENT
19
+ using Zenject;
20
+ #endif
21
+
22
+ public sealed class ComparisonPerformanceTests : BenchmarkTestBase
23
+ {
24
+ protected override bool MessagingDebugEnabled => false;
25
+
26
+ [Test]
27
+ public void Benchmark()
28
+ {
29
+ string operatingSystemSection = BenchmarkDocumentation.GetOperatingSystemSection();
30
+ string sectionName = string.IsNullOrEmpty(operatingSystemSection)
31
+ ? null
32
+ : $"Comparisons ({operatingSystemSection})";
33
+
34
+ BenchmarkSession session = new(
35
+ sectionName,
36
+ "### ",
37
+ new Func<string>[]
38
+ {
39
+ BenchmarkDocumentation.TryFindComparisonsDocPath,
40
+ BenchmarkDocumentation.TryFindPerformanceDocPath,
41
+ BenchmarkDocumentation.TryFindReadmePath,
42
+ }
43
+ );
44
+
45
+ RunWithSession(
46
+ session,
47
+ () =>
48
+ {
49
+ TimeSpan timeout = TimeSpan.FromSeconds(5);
50
+ BenchmarkDxMessaging(timeout);
51
+ BenchmarkUniRx(timeout);
52
+ BenchmarkMessagePipe(timeout);
53
+ BenchmarkZenjectSignals(timeout);
54
+ }
55
+ );
56
+ }
57
+
58
+ private void BenchmarkDxMessaging(TimeSpan timeout)
59
+ {
60
+ Stopwatch timer = Stopwatch.StartNew();
61
+ SimpleUntargetedMessage message = new();
62
+
63
+ RunWithComponent(component =>
64
+ {
65
+ int count = 0;
66
+ MessageRegistrationToken token = GetToken(component);
67
+ token.RegisterUntargeted<SimpleUntargetedMessage>(Handle);
68
+
69
+ message.EmitUntargeted();
70
+
71
+ timer.Restart();
72
+ do
73
+ {
74
+ for (int i = 0; i < NumInvocationsPerIteration; ++i)
75
+ {
76
+ message.EmitUntargeted();
77
+ }
78
+ } while (timer.Elapsed < timeout);
79
+
80
+ bool allocating;
81
+ try
82
+ {
83
+ Assert.That(() => message.EmitUntargeted(), Is.Not.AllocatingGCMemory());
84
+ allocating = false;
85
+ }
86
+ catch
87
+ {
88
+ allocating = true;
89
+ }
90
+
91
+ RecordBenchmark("DxMessaging (Untargeted) - No-Copy", count, timeout, allocating);
92
+ return;
93
+
94
+ void Handle(ref SimpleUntargetedMessage _)
95
+ {
96
+ ++count;
97
+ }
98
+ });
99
+ }
100
+
101
+ #if ZENJECT_PRESENT
102
+ private void BenchmarkZenjectSignals(TimeSpan timeout)
103
+ {
104
+ ZenjectBridge bridge = ZenjectBridge.Create();
105
+ if (bridge == null)
106
+ {
107
+ Debug.LogWarning("Zenject SignalBus not found. Skipping comparison benchmark.");
108
+ return;
109
+ }
110
+
111
+ SimpleUntargetedMessage message = new();
112
+ int count = 0;
113
+ using IDisposable subscription = bridge.Subscribe(_ => ++count);
114
+
115
+ bridge.Publish(message);
116
+
117
+ Stopwatch timer = Stopwatch.StartNew();
118
+ do
119
+ {
120
+ for (int i = 0; i < NumInvocationsPerIteration; ++i)
121
+ {
122
+ bridge.Publish(message);
123
+ }
124
+ } while (timer.Elapsed < timeout);
125
+
126
+ bool allocating;
127
+ try
128
+ {
129
+ Assert.That(() => bridge.Publish(message), Is.Not.AllocatingGCMemory());
130
+ allocating = false;
131
+ }
132
+ catch
133
+ {
134
+ allocating = true;
135
+ }
136
+
137
+ RecordBenchmark("Zenject SignalBus", count, timeout, allocating);
138
+ }
139
+ #else
140
+ private void BenchmarkZenjectSignals(TimeSpan timeout)
141
+ {
142
+ Debug.LogWarning("Zenject package not detected. Skipping comparison benchmark.");
143
+ }
144
+ #endif
145
+
146
+ #if UNIRX_PRESENT
147
+ private void BenchmarkUniRx(TimeSpan timeout)
148
+ {
149
+ UniRxBridge bridge = UniRxBridge.Create();
150
+ if (bridge == null)
151
+ {
152
+ Debug.LogWarning("UniRx.MessageBroker not found. Skipping comparison benchmark.");
153
+ return;
154
+ }
155
+
156
+ SimpleUntargetedMessage message = new();
157
+ int count = 0;
158
+ using IDisposable subscription = bridge.Subscribe(_ => ++count);
159
+
160
+ bridge.Publish(message);
161
+
162
+ Stopwatch timer = Stopwatch.StartNew();
163
+ do
164
+ {
165
+ for (int i = 0; i < NumInvocationsPerIteration; ++i)
166
+ {
167
+ bridge.Publish(message);
168
+ }
169
+ } while (timer.Elapsed < timeout);
170
+
171
+ bool allocating;
172
+ try
173
+ {
174
+ Assert.That(() => bridge.Publish(message), Is.Not.AllocatingGCMemory());
175
+ allocating = false;
176
+ }
177
+ catch
178
+ {
179
+ allocating = true;
180
+ }
181
+
182
+ RecordBenchmark("UniRx MessageBroker", count, timeout, allocating);
183
+ }
184
+ #else
185
+ private void BenchmarkUniRx(TimeSpan timeout)
186
+ {
187
+ Debug.LogWarning("UniRx package not detected. Skipping comparison benchmark.");
188
+ }
189
+ #endif
190
+
191
+ #if MESSAGEPIPE_PRESENT
192
+ private void BenchmarkMessagePipe(TimeSpan timeout)
193
+ {
194
+ MessagePipeBridge bridge = MessagePipeBridge.Create();
195
+ if (bridge == null)
196
+ {
197
+ Debug.LogWarning("Cysharp.MessagePipe not found. Skipping comparison benchmark.");
198
+ return;
199
+ }
200
+
201
+ SimpleUntargetedMessage message = new();
202
+ int count = 0;
203
+ using IDisposable subscription = bridge.Subscribe(_ => ++count);
204
+
205
+ bridge.Publish(message);
206
+
207
+ Stopwatch timer = Stopwatch.StartNew();
208
+ do
209
+ {
210
+ for (int i = 0; i < NumInvocationsPerIteration; ++i)
211
+ {
212
+ bridge.Publish(message);
213
+ }
214
+ } while (timer.Elapsed < timeout);
215
+
216
+ bool allocating;
217
+ try
218
+ {
219
+ Assert.That(() => bridge.Publish(message), Is.Not.AllocatingGCMemory());
220
+ allocating = false;
221
+ }
222
+ catch
223
+ {
224
+ allocating = true;
225
+ }
226
+
227
+ RecordBenchmark("MessagePipe (Global)", count, timeout, allocating);
228
+ }
229
+ #else
230
+ private void BenchmarkMessagePipe(TimeSpan timeout)
231
+ {
232
+ Debug.LogWarning("MessagePipe package not detected. Skipping comparison benchmark.");
233
+ }
234
+ #endif
235
+
236
+ #if UNIRX_PRESENT
237
+ private sealed class UniRxBridge
238
+ {
239
+ private readonly IMessageBroker _broker;
240
+
241
+ private UniRxBridge(IMessageBroker broker)
242
+ {
243
+ _broker = broker;
244
+ }
245
+
246
+ internal static UniRxBridge Create()
247
+ {
248
+ IMessageBroker broker = MessageBroker.Default;
249
+ if (broker == null)
250
+ {
251
+ return null;
252
+ }
253
+
254
+ return new UniRxBridge(broker);
255
+ }
256
+
257
+ internal IDisposable Subscribe(Action<SimpleUntargetedMessage> handler)
258
+ {
259
+ return _broker.Receive<SimpleUntargetedMessage>().Subscribe(handler);
260
+ }
261
+
262
+ internal void Publish(in SimpleUntargetedMessage message)
263
+ {
264
+ _broker.Publish(message);
265
+ }
266
+ }
267
+ #endif
268
+
269
+ #if MESSAGEPIPE_PRESENT
270
+ private sealed class MessagePipeBridge
271
+ {
272
+ private readonly IPublisher<SimpleUntargetedMessage> _publisher;
273
+ private readonly ISubscriber<SimpleUntargetedMessage> _subscriber;
274
+
275
+ private MessagePipeBridge(
276
+ IPublisher<SimpleUntargetedMessage> publisher,
277
+ ISubscriber<SimpleUntargetedMessage> subscriber
278
+ )
279
+ {
280
+ _publisher = publisher;
281
+ _subscriber = subscriber;
282
+ }
283
+
284
+ internal static MessagePipeBridge Create()
285
+ {
286
+ try
287
+ {
288
+ BuiltinContainerBuilder builder = new();
289
+ builder.AddMessagePipe();
290
+ builder.AddMessageBroker<SimpleUntargetedMessage>();
291
+ IServiceProvider provider = builder.BuildServiceProvider();
292
+ GlobalMessagePipe.SetProvider(provider);
293
+ IPublisher<SimpleUntargetedMessage> publisher =
294
+ GlobalMessagePipe.GetPublisher<SimpleUntargetedMessage>();
295
+ ISubscriber<SimpleUntargetedMessage> subscriber =
296
+ GlobalMessagePipe.GetSubscriber<SimpleUntargetedMessage>();
297
+ if (publisher == null || subscriber == null)
298
+ {
299
+ if (provider is IDisposable disposable)
300
+ {
301
+ disposable.Dispose();
302
+ }
303
+ Debug.LogWarning(
304
+ "MessagePipe publisher or subscriber could not be resolved."
305
+ );
306
+ return null;
307
+ }
308
+
309
+ return new MessagePipeBridge(publisher, subscriber);
310
+ }
311
+ catch (Exception exception)
312
+ {
313
+ Debug.LogWarning($"MessagePipe setup failed: {exception}");
314
+ return null;
315
+ }
316
+ }
317
+
318
+ internal IDisposable Subscribe(Action<SimpleUntargetedMessage> handler)
319
+ {
320
+ return _subscriber.Subscribe(handler);
321
+ }
322
+
323
+ internal void Publish(in SimpleUntargetedMessage message)
324
+ {
325
+ _publisher.Publish(message);
326
+ }
327
+ }
328
+ #endif
329
+
330
+ #if ZENJECT_PRESENT
331
+ private sealed class ZenjectBridge
332
+ {
333
+ private readonly SignalBus _signalBus;
334
+
335
+ private ZenjectBridge(SignalBus signalBus)
336
+ {
337
+ _signalBus = signalBus;
338
+ }
339
+
340
+ internal static ZenjectBridge Create()
341
+ {
342
+ try
343
+ {
344
+ DiContainer container = new();
345
+ SignalBusInstaller.Install(container);
346
+ container.DeclareSignal<SimpleUntargetedMessage>();
347
+ container.ResolveRoots();
348
+ SignalBus signalBus = container.Resolve<SignalBus>();
349
+ return new ZenjectBridge(signalBus);
350
+ }
351
+ catch (Exception exception)
352
+ {
353
+ Debug.LogWarning($"Zenject SignalBus setup failed: {exception}");
354
+ return null;
355
+ }
356
+ }
357
+
358
+ internal IDisposable Subscribe(Action<SimpleUntargetedMessage> handler)
359
+ {
360
+ return new Subscription(_signalBus, handler);
361
+ }
362
+
363
+ internal void Publish(in SimpleUntargetedMessage message)
364
+ {
365
+ _signalBus.Fire(message);
366
+ }
367
+
368
+ private sealed class Subscription : IDisposable
369
+ {
370
+ private readonly SignalBus _signalBus;
371
+ private readonly Action<SimpleUntargetedMessage> _handler;
372
+ private bool _disposed;
373
+
374
+ internal Subscription(SignalBus signalBus, Action<SimpleUntargetedMessage> handler)
375
+ {
376
+ _signalBus = signalBus;
377
+ _handler = handler;
378
+ _signalBus.Subscribe(handler);
379
+ }
380
+
381
+ public void Dispose()
382
+ {
383
+ if (_disposed)
384
+ {
385
+ return;
386
+ }
387
+
388
+ _signalBus.TryUnsubscribe(_handler);
389
+ _disposed = true;
390
+ }
391
+ }
392
+ }
393
+ #endif
394
+ }
395
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: f4e0156a9d3e4fc997620b462733ccc8
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: