com.wallstop-studios.dxmessaging 2.1.2 → 2.1.4

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 (67) hide show
  1. package/.github/workflows/dotnet-tests.yml +3 -3
  2. package/.github/workflows/prettier-autofix.yml +0 -7
  3. package/.pre-commit-config.yaml +8 -5
  4. package/AGENTS.md +12 -12
  5. package/CONTRIBUTING.md +8 -2
  6. package/Docs/Comparisons.md +5 -5
  7. package/Docs/InterceptorsAndOrdering.md +1 -1
  8. package/Docs/Performance.md +13 -13
  9. package/Docs/QuickReference.md +1 -1
  10. package/Docs/Reference.md +5 -5
  11. package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll +0 -0
  12. package/Editor/CustomEditors/MessagingComponentEditor.cs +3 -0
  13. package/Editor/DxMessagingEditorInitializer.cs +58 -1
  14. package/Editor/DxMessagingMenu.cs +38 -0
  15. package/Editor/DxMessagingMenu.cs.meta +11 -0
  16. package/Editor/DxMessagingSceneBuildProcessor.cs +81 -0
  17. package/Editor/DxMessagingSceneBuildProcessor.cs.meta +11 -0
  18. package/Editor/Settings/DxMessagingSettings.cs +37 -6
  19. package/Editor/Settings/DxMessagingSettingsProvider.cs +45 -7
  20. package/README.md +1 -1
  21. package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs +52 -0
  22. package/Runtime/Core/DataStructure/CyclicBuffer.cs +16 -0
  23. package/Runtime/Core/Diagnostics/MessageEmissionData.cs +1 -1
  24. package/Runtime/Core/Diagnostics/MessageRegistrationType.cs +62 -0
  25. package/Runtime/Core/DxMessagingStaticState.cs +108 -0
  26. package/Runtime/Core/DxMessagingStaticState.cs.meta +11 -0
  27. package/Runtime/Core/Extensions/IListExtensions.cs +24 -0
  28. package/Runtime/Core/Extensions/MessageBusExtensions.cs +142 -0
  29. package/Runtime/Core/Helper/MessageCache.cs +16 -0
  30. package/Runtime/Core/Helper/MessageHelperIndexer.cs +77 -0
  31. package/Runtime/Core/InstanceId.cs +86 -0
  32. package/Runtime/Core/MessageBus/DiagnosticsTarget.cs +31 -0
  33. package/Runtime/Core/MessageBus/DiagnosticsTarget.cs.meta +11 -0
  34. package/Runtime/Core/MessageBus/IMessageBus.cs +44 -16
  35. package/Runtime/Core/MessageBus/MessageBus.cs +167 -180
  36. package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs +44 -0
  37. package/Runtime/Core/MessageBus/MessagingRegistration.cs +60 -2
  38. package/Runtime/Core/MessageBus/RegistrationLog.cs +10 -0
  39. package/Runtime/Core/MessageHandler.cs +107 -6
  40. package/Runtime/Core/MessageRegistrationHandle.cs +59 -0
  41. package/Runtime/Core/MessageRegistrationToken.cs +18 -2
  42. package/Runtime/Core/Messages/ReflexiveMessage.cs +38 -0
  43. package/Runtime/Core/MessagingDebug.cs +16 -1
  44. package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs +4 -0
  45. package/Runtime/Unity/DxMessagingRuntimeInitializer.cs +19 -0
  46. package/Runtime/Unity/DxMessagingRuntimeInitializer.cs.meta +11 -0
  47. package/Runtime/Unity/InitialGlobalMessageBusProvider.cs +4 -0
  48. package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs +17 -0
  49. package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs +8 -0
  50. package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs +12 -0
  51. package/Runtime/Unity/MessagingComponent.cs +93 -0
  52. package/Samples~/DI/README.md +13 -13
  53. package/Samples~/Mini Combat/README.md +15 -15
  54. package/Samples~/Mini Combat/Walkthrough.md +12 -12
  55. package/Samples~/UI Buttons + Inspector/README.md +4 -4
  56. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoConstructorGenerator.cs +4 -0
  57. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxMessageIdGenerator.cs +4 -0
  58. package/Tests/Runtime/Core/DiagnosticsTests.cs +3 -3
  59. package/Tests/Runtime/Core/DxMessagingStaticStateTests.cs +69 -0
  60. package/Tests/Runtime/Core/DxMessagingStaticStateTests.cs.meta +11 -0
  61. package/Tests/Runtime/Core/Extensions/MessageBusExtensionsTests.cs +12 -31
  62. package/Tests/Runtime/Core/OrderingManyRegistrationsTests.cs +683 -0
  63. package/Tests/Runtime/Core/OrderingManyRegistrationsTests.cs.meta +11 -0
  64. package/package.json +1 -1
  65. package/scripts/fix-eol.js +38 -3
  66. package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj +0 -20
  67. package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj.meta +0 -7
@@ -13,6 +13,13 @@ namespace DxMessaging.Core.Extensions
13
13
  /// </summary>
14
14
  public static class MessageBusExtensions
15
15
  {
16
+ /// <summary>
17
+ /// Emits an untargeted message instance through the provided message bus.
18
+ /// </summary>
19
+ /// <typeparam name="TMessage">Concrete message type implementing <see cref="IUntargetedMessage"/>.</typeparam>
20
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
21
+ /// <param name="message">Message instance to send.</param>
22
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
16
23
  public static void EmitUntargeted<TMessage>(this IMessageBus messageBus, TMessage message)
17
24
  where TMessage : class, IUntargetedMessage
18
25
  {
@@ -24,6 +31,13 @@ namespace DxMessaging.Core.Extensions
24
31
  message.EmitUntargeted(messageBus);
25
32
  }
26
33
 
34
+ /// <summary>
35
+ /// Emits an untargeted struct message through the provided message bus without copying the payload.
36
+ /// </summary>
37
+ /// <typeparam name="TMessage">Concrete message type implementing <see cref="IUntargetedMessage"/>.</typeparam>
38
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
39
+ /// <param name="message">Reference to the struct message to send.</param>
40
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
27
41
  public static void EmitUntargeted<TMessage>(
28
42
  this IMessageBus messageBus,
29
43
  ref TMessage message
@@ -38,6 +52,21 @@ namespace DxMessaging.Core.Extensions
38
52
  message.EmitUntargeted(messageBus);
39
53
  }
40
54
 
55
+ /// <summary>
56
+ /// Emits a targeted message to the specified recipient.
57
+ /// </summary>
58
+ /// <typeparam name="TMessage">Concrete message type implementing <see cref="ITargetedMessage"/>.</typeparam>
59
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
60
+ /// <param name="target">Recipient of the message.</param>
61
+ /// <param name="message">Message instance to deliver.</param>
62
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
63
+ /// <example>
64
+ /// <code>
65
+ /// InstanceId playerId = GetPlayerId();
66
+ /// var change = new HealthChanged(5);
67
+ /// bus.EmitTargeted(playerId, change);
68
+ /// </code>
69
+ /// </example>
41
70
  public static void EmitTargeted<TMessage>(
42
71
  this IMessageBus messageBus,
43
72
  InstanceId target,
@@ -53,6 +82,14 @@ namespace DxMessaging.Core.Extensions
53
82
  message.EmitTargeted(target, messageBus);
54
83
  }
55
84
 
85
+ /// <summary>
86
+ /// Emits a targeted struct message to the specified recipient without copying the payload.
87
+ /// </summary>
88
+ /// <typeparam name="TMessage">Concrete message type implementing <see cref="ITargetedMessage"/>.</typeparam>
89
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
90
+ /// <param name="target">Recipient of the message.</param>
91
+ /// <param name="message">Reference to the struct message to deliver.</param>
92
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
56
93
  public static void EmitTargeted<TMessage>(
57
94
  this IMessageBus messageBus,
58
95
  InstanceId target,
@@ -68,6 +105,14 @@ namespace DxMessaging.Core.Extensions
68
105
  message.EmitTargeted(target, messageBus);
69
106
  }
70
107
 
108
+ /// <summary>
109
+ /// Emits a broadcast message sourced from the specified instance.
110
+ /// </summary>
111
+ /// <typeparam name="TMessage">Concrete message type implementing <see cref="IBroadcastMessage"/>.</typeparam>
112
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
113
+ /// <param name="source">Originating instance for the broadcast.</param>
114
+ /// <param name="message">Message instance to deliver.</param>
115
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
71
116
  public static void EmitBroadcast<TMessage>(
72
117
  this IMessageBus messageBus,
73
118
  InstanceId source,
@@ -83,6 +128,14 @@ namespace DxMessaging.Core.Extensions
83
128
  message.EmitBroadcast(source, messageBus);
84
129
  }
85
130
 
131
+ /// <summary>
132
+ /// Emits a broadcast struct message sourced from the specified instance without copying the payload.
133
+ /// </summary>
134
+ /// <typeparam name="TMessage">Concrete message type implementing <see cref="IBroadcastMessage"/>.</typeparam>
135
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
136
+ /// <param name="source">Originating instance for the broadcast.</param>
137
+ /// <param name="message">Reference to the struct message to deliver.</param>
138
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
86
139
  public static void EmitBroadcast<TMessage>(
87
140
  this IMessageBus messageBus,
88
141
  InstanceId source,
@@ -99,6 +152,14 @@ namespace DxMessaging.Core.Extensions
99
152
  }
100
153
 
101
154
  #if UNITY_2021_3_OR_NEWER
155
+ /// <summary>
156
+ /// Emits a targeted message to the specified Unity <see cref="GameObject"/>.
157
+ /// </summary>
158
+ /// <typeparam name="TMessage">Concrete message type implementing <see cref="ITargetedMessage"/>.</typeparam>
159
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
160
+ /// <param name="target">Unity object that will receive the message.</param>
161
+ /// <param name="message">Message instance to deliver.</param>
162
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
102
163
  public static void EmitGameObjectTargeted<TMessage>(
103
164
  this IMessageBus messageBus,
104
165
  GameObject target,
@@ -114,6 +175,14 @@ namespace DxMessaging.Core.Extensions
114
175
  message.EmitGameObjectTargeted(target, messageBus);
115
176
  }
116
177
 
178
+ /// <summary>
179
+ /// Emits a targeted struct message to the specified Unity <see cref="GameObject"/> without copying the payload.
180
+ /// </summary>
181
+ /// <typeparam name="TMessage">Concrete message type implementing <see cref="ITargetedMessage"/>.</typeparam>
182
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
183
+ /// <param name="target">Unity object that will receive the message.</param>
184
+ /// <param name="message">Reference to the struct message to deliver.</param>
185
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
117
186
  public static void EmitGameObjectTargeted<TMessage>(
118
187
  this IMessageBus messageBus,
119
188
  GameObject target,
@@ -129,6 +198,14 @@ namespace DxMessaging.Core.Extensions
129
198
  message.EmitGameObjectTargeted(target, messageBus);
130
199
  }
131
200
 
201
+ /// <summary>
202
+ /// Emits a targeted message to the specified Unity <see cref="Component"/>.
203
+ /// </summary>
204
+ /// <typeparam name="TMessage">Concrete message type implementing <see cref="ITargetedMessage"/>.</typeparam>
205
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
206
+ /// <param name="target">Unity component that will receive the message.</param>
207
+ /// <param name="message">Message instance to deliver.</param>
208
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
132
209
  public static void EmitComponentTargeted<TMessage>(
133
210
  this IMessageBus messageBus,
134
211
  Component target,
@@ -144,6 +221,14 @@ namespace DxMessaging.Core.Extensions
144
221
  message.EmitComponentTargeted(target, messageBus);
145
222
  }
146
223
 
224
+ /// <summary>
225
+ /// Emits a targeted struct message to the specified Unity <see cref="Component"/> without copying the payload.
226
+ /// </summary>
227
+ /// <typeparam name="TMessage">Concrete message type implementing <see cref="ITargetedMessage"/>.</typeparam>
228
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
229
+ /// <param name="target">Unity component that will receive the message.</param>
230
+ /// <param name="message">Reference to the struct message to deliver.</param>
231
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
147
232
  public static void EmitComponentTargeted<TMessage>(
148
233
  this IMessageBus messageBus,
149
234
  Component target,
@@ -159,6 +244,14 @@ namespace DxMessaging.Core.Extensions
159
244
  message.EmitComponentTargeted(target, messageBus);
160
245
  }
161
246
 
247
+ /// <summary>
248
+ /// Emits a broadcast message from the specified Unity <see cref="GameObject"/>.
249
+ /// </summary>
250
+ /// <typeparam name="TMessage">Concrete message type implementing <see cref="IBroadcastMessage"/>.</typeparam>
251
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
252
+ /// <param name="source">Unity object that is broadcasting the message.</param>
253
+ /// <param name="message">Message instance to deliver.</param>
254
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
162
255
  public static void EmitGameObjectBroadcast<TMessage>(
163
256
  this IMessageBus messageBus,
164
257
  GameObject source,
@@ -174,6 +267,14 @@ namespace DxMessaging.Core.Extensions
174
267
  message.EmitGameObjectBroadcast(source, messageBus);
175
268
  }
176
269
 
270
+ /// <summary>
271
+ /// Emits a broadcast struct message from the specified Unity <see cref="GameObject"/> without copying the payload.
272
+ /// </summary>
273
+ /// <typeparam name="TMessage">Concrete message type implementing <see cref="IBroadcastMessage"/>.</typeparam>
274
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
275
+ /// <param name="source">Unity object that is broadcasting the message.</param>
276
+ /// <param name="message">Reference to the struct message to deliver.</param>
277
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
177
278
  public static void EmitGameObjectBroadcast<TMessage>(
178
279
  this IMessageBus messageBus,
179
280
  GameObject source,
@@ -189,6 +290,14 @@ namespace DxMessaging.Core.Extensions
189
290
  message.EmitGameObjectBroadcast(source, messageBus);
190
291
  }
191
292
 
293
+ /// <summary>
294
+ /// Emits a broadcast message from the specified Unity <see cref="Component"/>.
295
+ /// </summary>
296
+ /// <typeparam name="TMessage">Concrete message type implementing <see cref="IBroadcastMessage"/>.</typeparam>
297
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
298
+ /// <param name="source">Unity component that is broadcasting the message.</param>
299
+ /// <param name="message">Message instance to deliver.</param>
300
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
192
301
  public static void EmitComponentBroadcast<TMessage>(
193
302
  this IMessageBus messageBus,
194
303
  Component source,
@@ -204,6 +313,14 @@ namespace DxMessaging.Core.Extensions
204
313
  message.EmitComponentBroadcast(source, messageBus);
205
314
  }
206
315
 
316
+ /// <summary>
317
+ /// Emits a broadcast struct message from the specified Unity <see cref="Component"/> without copying the payload.
318
+ /// </summary>
319
+ /// <typeparam name="TMessage">Concrete message type implementing <see cref="IBroadcastMessage"/>.</typeparam>
320
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
321
+ /// <param name="source">Unity component that is broadcasting the message.</param>
322
+ /// <param name="message">Reference to the struct message to deliver.</param>
323
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
207
324
  public static void EmitComponentBroadcast<TMessage>(
208
325
  this IMessageBus messageBus,
209
326
  Component source,
@@ -220,6 +337,17 @@ namespace DxMessaging.Core.Extensions
220
337
  }
221
338
  #endif
222
339
 
340
+ /// <summary>
341
+ /// Emits a string payload using the string-message utility channel.
342
+ /// </summary>
343
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
344
+ /// <param name="payload">Message text to broadcast globally.</param>
345
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
346
+ /// <example>
347
+ /// <code>
348
+ /// bus.Emit("PlayerJoined");
349
+ /// </code>
350
+ /// </example>
223
351
  public static void Emit(this IMessageBus messageBus, string payload)
224
352
  {
225
353
  if (messageBus == null)
@@ -230,6 +358,13 @@ namespace DxMessaging.Core.Extensions
230
358
  payload.Emit(messageBus);
231
359
  }
232
360
 
361
+ /// <summary>
362
+ /// Emits a string payload targeted at the specified instance.
363
+ /// </summary>
364
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
365
+ /// <param name="target">Intended recipient of the payload.</param>
366
+ /// <param name="payload">Message text to deliver.</param>
367
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
233
368
  public static void EmitAt(this IMessageBus messageBus, InstanceId target, string payload)
234
369
  {
235
370
  if (messageBus == null)
@@ -240,6 +375,13 @@ namespace DxMessaging.Core.Extensions
240
375
  payload.Emit(target, messageBus);
241
376
  }
242
377
 
378
+ /// <summary>
379
+ /// Emits a string payload broadcast from the specified instance.
380
+ /// </summary>
381
+ /// <param name="messageBus">Bus that should dispatch the message.</param>
382
+ /// <param name="source">Origin of the payload.</param>
383
+ /// <param name="payload">Message text to deliver.</param>
384
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
243
385
  public static void EmitFrom(this IMessageBus messageBus, InstanceId source, string payload)
244
386
  {
245
387
  if (messageBus == null)
@@ -33,6 +33,10 @@ namespace DxMessaging.Core.Helper
33
33
  }
34
34
 
35
35
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
36
+ /// <summary>
37
+ /// Advances the enumerator to the next cached value.
38
+ /// </summary>
39
+ /// <returns><c>true</c> if another non-null value exists; otherwise <c>false</c>.</returns>
36
40
  public bool MoveNext()
37
41
  {
38
42
  List<TValue> values = _cache._values;
@@ -55,12 +59,18 @@ namespace DxMessaging.Core.Helper
55
59
  object IEnumerator.Current => Current;
56
60
 
57
61
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
62
+ /// <summary>
63
+ /// Resets the enumerator to the position before the first element.
64
+ /// </summary>
58
65
  public void Reset()
59
66
  {
60
67
  _index = -1;
61
68
  _current = default;
62
69
  }
63
70
 
71
+ /// <summary>
72
+ /// Releases resources held by the enumerator.
73
+ /// </summary>
64
74
  public void Dispose() { }
65
75
  }
66
76
 
@@ -179,6 +189,12 @@ namespace DxMessaging.Core.Helper
179
189
  return GetEnumerator();
180
190
  }
181
191
 
192
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
193
+ internal void Clear()
194
+ {
195
+ _values.Clear();
196
+ }
197
+
182
198
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
183
199
  private void FillToIndex(int index)
184
200
  {
@@ -1,8 +1,80 @@
1
1
  namespace DxMessaging.Core.Helper
2
2
  {
3
+ using System;
4
+ using System.Collections.Generic;
5
+
3
6
  public static class MessageHelperIndexer
4
7
  {
8
+ internal readonly struct MessageHelperIndexerState
9
+ {
10
+ internal readonly int _totalMessages;
11
+
12
+ internal readonly Dictionary<Type, int> _sequentialIds;
13
+
14
+ internal MessageHelperIndexerState(
15
+ int totalMessages,
16
+ Dictionary<Type, int> sequentialIds
17
+ )
18
+ {
19
+ _totalMessages = totalMessages;
20
+ _sequentialIds = sequentialIds;
21
+ }
22
+ }
23
+
24
+ private static readonly object ResetLock = new();
25
+ private static readonly HashSet<Type> RegisteredTypes = new();
26
+ private static readonly Dictionary<Type, Func<int, int>> StateManipulationByType = new();
27
+
5
28
  internal static int TotalMessages = 0;
29
+
30
+ internal static void RegisterType(Type messageType, Func<int, int> idProducer)
31
+ {
32
+ if (messageType == null)
33
+ {
34
+ return;
35
+ }
36
+
37
+ lock (ResetLock)
38
+ {
39
+ if (!RegisteredTypes.Add(messageType))
40
+ {
41
+ return;
42
+ }
43
+
44
+ StateManipulationByType[messageType] = idProducer;
45
+ }
46
+ }
47
+
48
+ internal static MessageHelperIndexerState CaptureState()
49
+ {
50
+ lock (ResetLock)
51
+ {
52
+ Dictionary<Type, int> snapshot = new(RegisteredTypes.Count);
53
+ return new MessageHelperIndexerState(TotalMessages, snapshot);
54
+ }
55
+ }
56
+
57
+ internal static void RestoreState(MessageHelperIndexerState state)
58
+ {
59
+ lock (ResetLock)
60
+ {
61
+ TotalMessages = state._totalMessages;
62
+ foreach (KeyValuePair<Type, Func<int, int>> entry in StateManipulationByType)
63
+ {
64
+ Type type = entry.Key;
65
+ Func<int, int> manipulationAction = entry.Value;
66
+ if (
67
+ state._sequentialIds == null
68
+ || !state._sequentialIds.TryGetValue(type, out int value)
69
+ )
70
+ {
71
+ value = -1;
72
+ }
73
+
74
+ manipulationAction(value);
75
+ }
76
+ }
77
+ }
6
78
  }
7
79
 
8
80
  public static class MessageHelperIndexer<TMessage>
@@ -10,5 +82,10 @@ namespace DxMessaging.Core.Helper
10
82
  {
11
83
  // ReSharper disable once StaticMemberInGenericType
12
84
  internal static int SequentialId = -1;
85
+
86
+ static MessageHelperIndexer()
87
+ {
88
+ MessageHelperIndexer.RegisterType(typeof(TMessage), value => SequentialId = value);
89
+ }
13
90
  }
14
91
  }
@@ -35,6 +35,10 @@ namespace DxMessaging.Core
35
35
  public readonly UnityEngine.Object Object;
36
36
  #endif
37
37
 
38
+ /// <summary>
39
+ /// Creates an identifier that wraps the provided Unity instance ID.
40
+ /// </summary>
41
+ /// <param name="id">Unity instance ID to wrap.</param>
38
42
  public InstanceId(int id)
39
43
  {
40
44
  _id = id;
@@ -51,12 +55,22 @@ namespace DxMessaging.Core
51
55
  }
52
56
 
53
57
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
58
+ /// <summary>
59
+ /// Converts a <see cref="UnityEngine.GameObject"/> reference into an <see cref="InstanceId"/>.
60
+ /// </summary>
61
+ /// <param name="gameObject">GameObject to wrap.</param>
62
+ /// <returns>Instance identifier representing <paramref name="gameObject"/>.</returns>
54
63
  public static implicit operator InstanceId(UnityEngine.GameObject gameObject)
55
64
  {
56
65
  return new InstanceId(gameObject);
57
66
  }
58
67
 
59
68
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
69
+ /// <summary>
70
+ /// Converts a <see cref="UnityEngine.Component"/> reference into an <see cref="InstanceId"/>.
71
+ /// </summary>
72
+ /// <param name="component">Component to wrap.</param>
73
+ /// <returns>Instance identifier representing <paramref name="component"/>.</returns>
60
74
  public static implicit operator InstanceId(UnityEngine.Component component)
61
75
  {
62
76
  return new InstanceId(component);
@@ -64,23 +78,43 @@ namespace DxMessaging.Core
64
78
  #endif
65
79
 
66
80
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
81
+ /// <summary>
82
+ /// Checks for equality with another <see cref="InstanceId"/>.
83
+ /// </summary>
84
+ /// <param name="other">Other instance identifier.</param>
85
+ /// <returns><c>true</c> when both identifiers refer to the same Unity instance.</returns>
67
86
  public bool Equals(InstanceId other)
68
87
  {
69
88
  return _id == other._id;
70
89
  }
71
90
 
72
91
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
92
+ /// <summary>
93
+ /// Checks for equality with an arbitrary object.
94
+ /// </summary>
95
+ /// <param name="other">Object to compare.</param>
96
+ /// <returns>
97
+ /// <c>true</c> when <paramref name="other"/> is an <see cref="InstanceId"/> representing the same Unity instance.
98
+ /// </returns>
73
99
  public override bool Equals(object other)
74
100
  {
75
101
  return other is InstanceId id && Equals(id);
76
102
  }
77
103
 
78
104
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
105
+ /// <summary>
106
+ /// Gets a hash code suitable for dictionary or set lookups.
107
+ /// </summary>
108
+ /// <returns>Hash code derived from the underlying Unity instance ID.</returns>
79
109
  public override int GetHashCode()
80
110
  {
81
111
  return _id;
82
112
  }
83
113
 
114
+ /// <summary>
115
+ /// Returns a string representation that includes the Unity instance ID and, when available, the object name.
116
+ /// </summary>
117
+ /// <returns>Human-readable description of the identifier.</returns>
84
118
  public override string ToString()
85
119
  {
86
120
  #if UNITY_2021_3_OR_NEWER
@@ -93,48 +127,100 @@ namespace DxMessaging.Core
93
127
  }
94
128
 
95
129
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
130
+ /// <summary>
131
+ /// Determines whether two identifiers refer to the same Unity instance.
132
+ /// </summary>
133
+ /// <param name="lhs">Left-hand identifier.</param>
134
+ /// <param name="rhs">Right-hand identifier.</param>
135
+ /// <returns><c>true</c> when both identifiers represent the same value.</returns>
96
136
  public static bool operator ==(InstanceId lhs, InstanceId rhs)
97
137
  {
98
138
  return lhs._id == rhs._id;
99
139
  }
100
140
 
101
141
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
142
+ /// <summary>
143
+ /// Determines whether two identifiers refer to different Unity instances.
144
+ /// </summary>
145
+ /// <param name="lhs">Left-hand identifier.</param>
146
+ /// <param name="rhs">Right-hand identifier.</param>
147
+ /// <returns><c>true</c> when the identifiers represent different values.</returns>
102
148
  public static bool operator !=(InstanceId lhs, InstanceId rhs)
103
149
  {
104
150
  return lhs._id != rhs._id;
105
151
  }
106
152
 
107
153
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
154
+ /// <summary>
155
+ /// Compares two identifiers for ascending ordering.
156
+ /// </summary>
157
+ /// <param name="lhs">Left-hand identifier.</param>
158
+ /// <param name="rhs">Right-hand identifier.</param>
159
+ /// <returns><c>true</c> when <paramref name="lhs"/> precedes <paramref name="rhs"/>.</returns>
108
160
  public static bool operator <(InstanceId lhs, InstanceId rhs)
109
161
  {
110
162
  return lhs._id.CompareTo(rhs._id) < 0;
111
163
  }
112
164
 
113
165
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
166
+ /// <summary>
167
+ /// Compares two identifiers for ascending ordering with equality.
168
+ /// </summary>
169
+ /// <param name="lhs">Left-hand identifier.</param>
170
+ /// <param name="rhs">Right-hand identifier.</param>
171
+ /// <returns>
172
+ /// <c>true</c> when <paramref name="lhs"/> precedes <paramref name="rhs"/> or both identifiers are equal.
173
+ /// </returns>
114
174
  public static bool operator <=(InstanceId lhs, InstanceId rhs)
115
175
  {
116
176
  return lhs._id.CompareTo(rhs._id) <= 0;
117
177
  }
118
178
 
119
179
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
180
+ /// <summary>
181
+ /// Compares two identifiers for descending ordering.
182
+ /// </summary>
183
+ /// <param name="lhs">Left-hand identifier.</param>
184
+ /// <param name="rhs">Right-hand identifier.</param>
185
+ /// <returns><c>true</c> when <paramref name="lhs"/> follows <paramref name="rhs"/>.</returns>
120
186
  public static bool operator >(InstanceId lhs, InstanceId rhs)
121
187
  {
122
188
  return lhs._id.CompareTo(rhs._id) > 0;
123
189
  }
124
190
 
125
191
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
192
+ /// <summary>
193
+ /// Compares two identifiers for descending ordering with equality.
194
+ /// </summary>
195
+ /// <param name="lhs">Left-hand identifier.</param>
196
+ /// <param name="rhs">Right-hand identifier.</param>
197
+ /// <returns>
198
+ /// <c>true</c> when <paramref name="lhs"/> follows <paramref name="rhs"/> or both identifiers are equal.
199
+ /// </returns>
126
200
  public static bool operator >=(InstanceId lhs, InstanceId rhs)
127
201
  {
128
202
  return lhs._id.CompareTo(rhs._id) >= 0;
129
203
  }
130
204
 
131
205
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
206
+ /// <summary>
207
+ /// Compares this identifier with another identifier for ordering.
208
+ /// </summary>
209
+ /// <param name="other">Identifier to compare with.</param>
210
+ /// <returns>Relative ordering as defined by <see cref="IComparable{T}.CompareTo(T)"/>.</returns>
132
211
  public int CompareTo(InstanceId other)
133
212
  {
134
213
  return _id.CompareTo(other._id);
135
214
  }
136
215
 
137
216
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
217
+ /// <summary>
218
+ /// Compares this identifier with an arbitrary object for ordering.
219
+ /// </summary>
220
+ /// <param name="rhs">Object to compare with.</param>
221
+ /// <returns>
222
+ /// Relative ordering when <paramref name="rhs"/> is an <see cref="InstanceId"/>; otherwise <c>-1</c>.
223
+ /// </returns>
138
224
  public int CompareTo(object rhs)
139
225
  {
140
226
  if (rhs is InstanceId other)
@@ -0,0 +1,31 @@
1
+ namespace DxMessaging.Core.MessageBus
2
+ {
3
+ using System;
4
+
5
+ /// <summary>
6
+ /// Flags describing which execution targets should enable diagnostics by default.
7
+ /// </summary>
8
+ [Flags]
9
+ public enum DiagnosticsTarget
10
+ {
11
+ /// <summary>
12
+ /// Diagnostics are disabled.
13
+ /// </summary>
14
+ Off = 0,
15
+
16
+ /// <summary>
17
+ /// Diagnostics should run while in the Unity editor.
18
+ /// </summary>
19
+ Editor = 1,
20
+
21
+ /// <summary>
22
+ /// Diagnostics should run while in player/runtime builds.
23
+ /// </summary>
24
+ Runtime = 2,
25
+
26
+ /// <summary>
27
+ /// Diagnostics should run in both editor and runtime environments.
28
+ /// </summary>
29
+ All = Editor | Runtime,
30
+ }
31
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: d2ff6bbe0b187ff4ab1051164b721d67
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: