com.wallstop-studios.dxmessaging 2.1.1 → 2.1.3

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 (158) hide show
  1. package/.github/workflows/dotnet-tests.yml +72 -0
  2. package/.lychee.toml +4 -2
  3. package/AGENTS.md +13 -12
  4. package/Docs/Comparisons.md +5 -5
  5. package/Docs/Install.md +2 -1
  6. package/Docs/InterceptorsAndOrdering.md +1 -1
  7. package/Docs/Performance.md +15 -13
  8. package/Docs/QuickReference.md +1 -1
  9. package/Docs/Reference.md +5 -5
  10. package/Editor/Analyzers/Microsoft.CodeAnalysis.CSharp.dll +0 -0
  11. package/Editor/Analyzers/Microsoft.CodeAnalysis.CSharp.dll.meta +13 -2
  12. package/Editor/Analyzers/Microsoft.CodeAnalysis.dll +0 -0
  13. package/Editor/Analyzers/Microsoft.CodeAnalysis.dll.meta +11 -0
  14. package/Editor/Analyzers/System.Collections.Immutable.dll +0 -0
  15. package/Editor/Analyzers/System.Collections.Immutable.dll.meta +11 -0
  16. package/Editor/Analyzers/System.Reflection.Metadata.dll +0 -0
  17. package/Editor/Analyzers/System.Reflection.Metadata.dll.meta +13 -2
  18. package/Editor/Analyzers/System.Runtime.CompilerServices.Unsafe.dll +0 -0
  19. package/Editor/Analyzers/System.Runtime.CompilerServices.Unsafe.dll.meta +11 -0
  20. package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll +0 -0
  21. package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll.meta +3 -2
  22. package/Editor/AssemblyInfo.cs +3 -0
  23. package/Editor/AssemblyInfo.cs.meta +3 -0
  24. package/Editor/CustomEditors/MessagingComponentEditor.cs +24 -0
  25. package/Editor/DxMessagingEditorInitializer.cs +58 -1
  26. package/Editor/DxMessagingMenu.cs +38 -0
  27. package/Editor/DxMessagingMenu.cs.meta +11 -0
  28. package/Editor/DxMessagingSceneBuildProcessor.cs +81 -0
  29. package/Editor/DxMessagingSceneBuildProcessor.cs.meta +11 -0
  30. package/Editor/Settings/DxMessagingSettings.cs +37 -6
  31. package/Editor/Settings/DxMessagingSettingsProvider.cs +45 -7
  32. package/Editor/SetupCscRsp.cs +133 -53
  33. package/Editor/Testing/MessagingComponentEditorHarness.cs +218 -0
  34. package/Editor/Testing/MessagingComponentEditorHarness.cs.meta +3 -0
  35. package/Editor/Testing.meta +3 -0
  36. package/README.md +10 -4
  37. package/Runtime/AssemblyInfo.cs +1 -0
  38. package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs +52 -0
  39. package/Runtime/Core/DataStructure/CyclicBuffer.cs +16 -0
  40. package/Runtime/Core/Diagnostics/MessageEmissionData.cs +27 -12
  41. package/Runtime/Core/Diagnostics/MessageRegistrationType.cs +62 -0
  42. package/Runtime/Core/DxMessagingStaticState.cs +108 -0
  43. package/Runtime/Core/DxMessagingStaticState.cs.meta +11 -0
  44. package/Runtime/Core/Extensions/IListExtensions.cs +24 -0
  45. package/Runtime/Core/Extensions/MessageBusExtensions.cs +144 -2
  46. package/Runtime/Core/Extensions/MessageExtensions.cs +2 -2
  47. package/Runtime/Core/Helper/MessageCache.cs +16 -0
  48. package/Runtime/Core/Helper/MessageHelperIndexer.cs +77 -0
  49. package/Runtime/Core/InstanceId.cs +91 -3
  50. package/Runtime/Core/MessageBus/DiagnosticsTarget.cs +31 -0
  51. package/Runtime/Core/MessageBus/DiagnosticsTarget.cs.meta +11 -0
  52. package/Runtime/Core/MessageBus/IMessageBus.cs +44 -16
  53. package/Runtime/Core/MessageBus/MessageBus.cs +96 -25
  54. package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs +46 -2
  55. package/Runtime/Core/MessageBus/MessagingRegistration.cs +63 -5
  56. package/Runtime/Core/MessageBus/RegistrationLog.cs +10 -0
  57. package/Runtime/Core/MessageHandler.cs +141 -8
  58. package/Runtime/Core/MessageRegistrationHandle.cs +59 -0
  59. package/Runtime/Core/MessageRegistrationToken.cs +20 -4
  60. package/Runtime/Core/Messages/ReflexiveMessage.cs +38 -0
  61. package/Runtime/Core/MessagingDebug.cs +16 -1
  62. package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs +6 -0
  63. package/Runtime/Unity/DxMessagingRuntimeInitializer.cs +19 -0
  64. package/Runtime/Unity/DxMessagingRuntimeInitializer.cs.meta +11 -0
  65. package/Runtime/Unity/InitialGlobalMessageBusProvider.cs +6 -0
  66. package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs +19 -0
  67. package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs +10 -0
  68. package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs +14 -0
  69. package/Runtime/Unity/MessageAwareComponent.cs +2 -0
  70. package/Runtime/Unity/MessageBusProviderHandle.cs +4 -0
  71. package/Runtime/Unity/MessagingComponent.cs +109 -0
  72. package/Runtime/Unity/MessagingComponentInstaller.cs +2 -0
  73. package/Runtime/Unity/ScriptableMessageBusProvider.cs +2 -0
  74. package/Samples~/DI/README.md +13 -13
  75. package/Samples~/Mini Combat/README.md +15 -15
  76. package/Samples~/Mini Combat/Walkthrough.md +12 -12
  77. package/Samples~/UI Buttons + Inspector/README.md +4 -4
  78. package/SourceGenerators/Directory.Build.props +9 -0
  79. package/{Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj.meta → SourceGenerators/Directory.Build.props.meta} +1 -1
  80. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoConstructorGenerator.cs +23 -24
  81. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxMessageIdGenerator.cs +91 -27
  82. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj +24 -4
  83. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DocsSnippetCompilationTests.cs +193 -0
  84. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DocsSnippetCompilationTests.cs.meta +11 -0
  85. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DxAutoConstructorGeneratorDiagnosticsTests.cs +69 -0
  86. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DxAutoConstructorGeneratorDiagnosticsTests.cs.meta +11 -0
  87. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DxMessageIdGeneratorDiagnosticsTests.cs +66 -0
  88. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DxMessageIdGeneratorDiagnosticsTests.cs.meta +11 -0
  89. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/GeneratorTestUtilities.cs +155 -0
  90. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/GeneratorTestUtilities.cs.meta +11 -0
  91. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/WallstopStudios.DxMessaging.SourceGenerators.Tests.csproj +20 -0
  92. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/WallstopStudios.DxMessaging.SourceGenerators.Tests.csproj.meta +7 -0
  93. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests.meta +8 -0
  94. package/Tests/Editor/MessagingComponentEditorHarnessTests.cs +243 -0
  95. package/Tests/Editor/MessagingComponentEditorHarnessTests.cs.meta +3 -0
  96. package/Tests/Editor/MessagingComponentSerializationTests.cs +129 -0
  97. package/Tests/Editor/MessagingComponentSerializationTests.cs.meta +3 -0
  98. package/Tests/Editor/WallstopStudios.DxMessaging.Tests.Editor.asmdef +19 -0
  99. package/Tests/Editor/WallstopStudios.DxMessaging.Tests.Editor.asmdef.meta +3 -0
  100. package/Tests/Editor.meta +3 -0
  101. package/Tests/Runtime/Benchmarks/BenchmarkSession.cs +3 -0
  102. package/Tests/Runtime/Benchmarks/BenchmarkTestBase.cs +3 -0
  103. package/Tests/Runtime/Benchmarks/ComparisonPerformanceTests.cs +3 -0
  104. package/Tests/Runtime/Benchmarks/PerformanceTests.cs +137 -0
  105. package/Tests/Runtime/Core/AlternateBusTests.cs +3 -0
  106. package/Tests/Runtime/Core/BroadcastTests.cs +3 -0
  107. package/Tests/Runtime/Core/CyclicBufferTests.cs +3 -0
  108. package/Tests/Runtime/Core/DefaultBusFallbackTests.cs +5 -2
  109. package/Tests/Runtime/Core/DiagnosticsTests.cs +6 -3
  110. package/Tests/Runtime/Core/DxMessagingStaticStateTests.cs +69 -0
  111. package/Tests/Runtime/Core/DxMessagingStaticStateTests.cs.meta +11 -0
  112. package/Tests/Runtime/Core/EdgeCaseTests.cs +3 -0
  113. package/Tests/Runtime/Core/EnablementTests.cs +3 -0
  114. package/Tests/Runtime/Core/Extensions/MessageExtensionsProviderTests.cs +2 -2
  115. package/Tests/Runtime/Core/GenericMessageTests.cs +3 -0
  116. package/Tests/Runtime/Core/GlobalAcceptAllTests.cs +3 -0
  117. package/Tests/Runtime/Core/InterceptorCancellationTests.cs +3 -0
  118. package/Tests/Runtime/Core/LifecycleTests.cs +3 -0
  119. package/Tests/Runtime/Core/MessageEmissionDataTests.cs +70 -0
  120. package/Tests/Runtime/Core/MessageEmissionDataTests.cs.meta +11 -0
  121. package/Tests/Runtime/Core/MessagingComponentLifecycleTests.cs +3 -0
  122. package/Tests/Runtime/Core/MessagingTestBase.cs +3 -0
  123. package/Tests/Runtime/Core/MutationDedupeTests.cs +3 -0
  124. package/Tests/Runtime/Core/MutationDestructionTests.cs +3 -0
  125. package/Tests/Runtime/Core/MutationDuringEmissionTests.cs +3 -0
  126. package/Tests/Runtime/Core/MutationGlobalAddTests.cs +3 -0
  127. package/Tests/Runtime/Core/MutationInterceptorTests.cs +3 -0
  128. package/Tests/Runtime/Core/MutationPostProcessorAcrossHandlersTests.cs +3 -0
  129. package/Tests/Runtime/Core/MutationPostProcessorMoreTests.cs +3 -0
  130. package/Tests/Runtime/Core/MutationPriorityTests.cs +3 -0
  131. package/Tests/Runtime/Core/NominalTests.cs +3 -0
  132. package/Tests/Runtime/Core/OrderingTests.cs +3 -0
  133. package/Tests/Runtime/Core/OverDeregistrationTests.cs +3 -0
  134. package/Tests/Runtime/Core/PostProcessorTests.cs +3 -0
  135. package/Tests/Runtime/Core/ReflexiveErrorTests.cs +3 -0
  136. package/Tests/Runtime/Core/ReflexiveMessageWarningTests.cs +4 -1
  137. package/Tests/Runtime/Core/ReflexiveTests.cs +3 -0
  138. package/Tests/Runtime/Core/RegistrationTests.cs +3 -0
  139. package/Tests/Runtime/Core/StringShorthandTests.cs +3 -0
  140. package/Tests/Runtime/Core/TargetedTests.cs +3 -0
  141. package/Tests/Runtime/Core/TypedShorthandTests.cs +3 -0
  142. package/Tests/Runtime/Core/UntargetedEquivalenceTests.cs +3 -0
  143. package/Tests/Runtime/Core/UntargetedPrefreezeTests.cs +14 -78
  144. package/Tests/Runtime/Core/UntargetedTests.cs +3 -0
  145. package/Tests/Runtime/Integrations/Reflex/ReflexIntegrationTests.cs +4 -1
  146. package/Tests/Runtime/Integrations/VContainer/VContainerIntegrationTests.cs +3 -0
  147. package/Tests/Runtime/Integrations/Zenject/ZenjectIntegrationTests.cs +3 -0
  148. package/Tests/Runtime/Scripts/Components/GenericMessageAwareComponent.cs +3 -0
  149. package/Tests/Runtime/Scripts/Components/ManualListenerComponent.cs +3 -0
  150. package/Tests/Runtime/Scripts/Components/ReflexiveReceiverComponent.cs +3 -0
  151. package/Tests/Runtime/TestUtilities/UnityFixtureBase.cs +3 -0
  152. package/Tests/Runtime/Unity/MessageBusProviderAssetTests.cs +3 -0
  153. package/Tests/Runtime/Unity/MessageBusProviderHandleTests.cs +87 -3
  154. package/Tests/Runtime/Unity/MessagingComponentInstallerSceneTests.cs +109 -0
  155. package/Tests/Runtime/Unity/MessagingComponentInstallerSceneTests.cs.meta +11 -0
  156. package/Tests/Runtime/Unity/MessagingComponentProviderIntegrationTests.cs +159 -17
  157. package/package.json +1 -1
  158. package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj +0 -7
@@ -30,18 +30,24 @@ namespace DxMessaging.Core
30
30
 
31
31
  private readonly int _id;
32
32
 
33
- #if UNITY_2017_1_OR_NEWER
33
+ #if UNITY_2021_3_OR_NEWER
34
34
  // ReSharper disable once InconsistentNaming
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;
45
+ #if UNITY_2021_3_OR_NEWER
41
46
  Object = null;
47
+ #endif
42
48
  }
43
49
 
44
- #if UNITY_2017_1_OR_NEWER
50
+ #if UNITY_2021_3_OR_NEWER
45
51
  private InstanceId(UnityEngine.Object unityObject)
46
52
  {
47
53
  _id = unityObject.GetInstanceID();
@@ -49,12 +55,22 @@ namespace DxMessaging.Core
49
55
  }
50
56
 
51
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>
52
63
  public static implicit operator InstanceId(UnityEngine.GameObject gameObject)
53
64
  {
54
65
  return new InstanceId(gameObject);
55
66
  }
56
67
 
57
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>
58
74
  public static implicit operator InstanceId(UnityEngine.Component component)
59
75
  {
60
76
  return new InstanceId(component);
@@ -62,26 +78,46 @@ namespace DxMessaging.Core
62
78
  #endif
63
79
 
64
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>
65
86
  public bool Equals(InstanceId other)
66
87
  {
67
88
  return _id == other._id;
68
89
  }
69
90
 
70
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>
71
99
  public override bool Equals(object other)
72
100
  {
73
101
  return other is InstanceId id && Equals(id);
74
102
  }
75
103
 
76
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>
77
109
  public override int GetHashCode()
78
110
  {
79
111
  return _id;
80
112
  }
81
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>
82
118
  public override string ToString()
83
119
  {
84
- #if UNITY_2017_1_OR_NEWER
120
+ #if UNITY_2021_3_OR_NEWER
85
121
  UnityEngine.Object instance = Object;
86
122
  string objectName = instance == null ? string.Empty : instance.name;
87
123
  return new { Id = _id, Name = objectName }.ToString();
@@ -91,48 +127,100 @@ namespace DxMessaging.Core
91
127
  }
92
128
 
93
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>
94
136
  public static bool operator ==(InstanceId lhs, InstanceId rhs)
95
137
  {
96
138
  return lhs._id == rhs._id;
97
139
  }
98
140
 
99
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>
100
148
  public static bool operator !=(InstanceId lhs, InstanceId rhs)
101
149
  {
102
150
  return lhs._id != rhs._id;
103
151
  }
104
152
 
105
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>
106
160
  public static bool operator <(InstanceId lhs, InstanceId rhs)
107
161
  {
108
162
  return lhs._id.CompareTo(rhs._id) < 0;
109
163
  }
110
164
 
111
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>
112
174
  public static bool operator <=(InstanceId lhs, InstanceId rhs)
113
175
  {
114
176
  return lhs._id.CompareTo(rhs._id) <= 0;
115
177
  }
116
178
 
117
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>
118
186
  public static bool operator >(InstanceId lhs, InstanceId rhs)
119
187
  {
120
188
  return lhs._id.CompareTo(rhs._id) > 0;
121
189
  }
122
190
 
123
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>
124
200
  public static bool operator >=(InstanceId lhs, InstanceId rhs)
125
201
  {
126
202
  return lhs._id.CompareTo(rhs._id) >= 0;
127
203
  }
128
204
 
129
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>
130
211
  public int CompareTo(InstanceId other)
131
212
  {
132
213
  return _id.CompareTo(other._id);
133
214
  }
134
215
 
135
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>
136
224
  public int CompareTo(object rhs)
137
225
  {
138
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:
@@ -3,7 +3,11 @@ namespace DxMessaging.Core.MessageBus
3
3
  using System;
4
4
  using System.Threading;
5
5
  using Core;
6
+ using Extensions;
6
7
  using Messages;
8
+ #if UNITY_2021_3_OR_NEWER
9
+ using UnityEngine;
10
+ #endif
7
11
 
8
12
  /// <summary>
9
13
  /// Contract for a general-purpose message bus handling registration and dispatch.
@@ -41,31 +45,59 @@ namespace DxMessaging.Core.MessageBus
41
45
  /// <summary>
42
46
  /// Default diagnostics mode for newly created buses and tokens.
43
47
  /// </summary>
44
- public static bool GlobalDiagnosticsMode { get; set; }
48
+ static DiagnosticsTarget GlobalDiagnosticsTargets { get; set; } = DiagnosticsTarget.Off;
49
+
50
+ [Obsolete("Use GlobalDiagnosticsTargets instead.")]
51
+ static bool GlobalDiagnosticsMode
52
+ {
53
+ get => GlobalDiagnosticsTargets != DiagnosticsTarget.Off;
54
+ set => GlobalDiagnosticsTargets = value ? DiagnosticsTarget.All : DiagnosticsTarget.Off;
55
+ }
45
56
 
46
57
  long EmissionId { get; }
47
58
 
48
59
  /// <summary>
49
60
  /// Default ring buffer size for emission history when diagnostics are enabled.
50
61
  /// </summary>
51
- public static int GlobalMessageBufferSize { get; set; }
62
+ static int GlobalMessageBufferSize { get; set; }
52
63
 
53
64
  internal static int GlobalSequentialIndex = -1;
54
65
 
55
66
  protected static int GenerateNewGlobalSequentialIndex() =>
56
67
  Interlocked.Increment(ref GlobalSequentialIndex);
57
68
 
69
+ internal static bool ShouldEnableDiagnostics()
70
+ {
71
+ DiagnosticsTarget targets = GlobalDiagnosticsTargets;
72
+ if (targets == DiagnosticsTarget.Off)
73
+ {
74
+ return false;
75
+ }
76
+
77
+ #if UNITY_2021_3_OR_NEWER
78
+ if (Application.isEditor)
79
+ {
80
+ return targets.HasFlagNoAlloc(DiagnosticsTarget.Editor)
81
+ || targets.HasFlagNoAlloc(DiagnosticsTarget.Runtime);
82
+ }
83
+
84
+ return targets.HasFlagNoAlloc(DiagnosticsTarget.Editor);
85
+ #else
86
+ return targets.HasFlagNoAlloc(DiagnosticsTarget.Runtime);
87
+ #endif
88
+ }
89
+
58
90
  /// <summary>
59
91
  /// Whether diagnostics are recorded for this bus instance.
60
92
  /// </summary>
61
- public bool DiagnosticsMode { get; }
93
+ bool DiagnosticsMode { get; }
62
94
 
63
- public int RegisteredGlobalSequentialIndex { get; }
64
- public int RegisteredBroadcast { get; }
95
+ int RegisteredGlobalSequentialIndex { get; }
96
+ int RegisteredBroadcast { get; }
65
97
 
66
- public int RegisteredTargeted { get; }
98
+ int RegisteredTargeted { get; }
67
99
 
68
- public int RegisteredUntargeted { get; }
100
+ int RegisteredUntargeted { get; }
69
101
 
70
102
  /// <summary>
71
103
  /// Interceptor delegate for untargeted messages to transform or cancel them.
@@ -73,7 +105,7 @@ namespace DxMessaging.Core.MessageBus
73
105
  /// <typeparam name="TMessage">Specific type of message.</typeparam>
74
106
  /// <param name="message">Message to consider.</param>
75
107
  /// <returns>True if the message should be processed, false if it should be skipped.</returns>
76
- public delegate bool UntargetedInterceptor<TMessage>(ref TMessage message)
108
+ delegate bool UntargetedInterceptor<TMessage>(ref TMessage message)
77
109
  where TMessage : IUntargetedMessage;
78
110
 
79
111
  /// <summary>
@@ -83,10 +115,7 @@ namespace DxMessaging.Core.MessageBus
83
115
  /// <param name="target">Target of the message.</param>
84
116
  /// <param name="message">Message to consider.</param>
85
117
  /// <returns>True if the message should be processed, false if it should be skipped.</returns>
86
- public delegate bool TargetedInterceptor<TMessage>(
87
- ref InstanceId target,
88
- ref TMessage message
89
- )
118
+ delegate bool TargetedInterceptor<TMessage>(ref InstanceId target, ref TMessage message)
90
119
  where TMessage : ITargetedMessage;
91
120
 
92
121
  /// <summary>
@@ -96,10 +125,7 @@ namespace DxMessaging.Core.MessageBus
96
125
  /// <param name="source">Source of the message.</param>
97
126
  /// <param name="message">Message to consider.</param>
98
127
  /// <returns>True if the message should be processed, false if it should be skipped.</returns>
99
- public delegate bool BroadcastInterceptor<TMessage>(
100
- ref InstanceId source,
101
- ref TMessage message
102
- )
128
+ delegate bool BroadcastInterceptor<TMessage>(ref InstanceId source, ref TMessage message)
103
129
  where TMessage : IBroadcastMessage;
104
130
 
105
131
  /// <summary>
@@ -149,6 +175,7 @@ namespace DxMessaging.Core.MessageBus
149
175
  /// <typeparam name="T">Type of the BroadcastMessage to register.</typeparam>
150
176
  /// <param name="source">InstanceId of the source for BroadcastMessages to listen to.</param>
151
177
  /// <param name="messageHandler">MessageHandler to register to accept BroadcastMessages.</param>
178
+ /// <param name="priority"></param>
152
179
  /// <returns>The deregistration action. Should be invoked when the handler no longer wants to receive messages.</returns>
153
180
  Action RegisterSourcedBroadcast<T>(
154
181
  InstanceId source,
@@ -163,6 +190,7 @@ namespace DxMessaging.Core.MessageBus
163
190
  /// </summary>
164
191
  /// <typeparam name="T">Type of the BroadcastMessage to register.</typeparam>
165
192
  /// <param name="messageHandler">MessageHandler to register to accept BroadcastMessages.</param>
193
+ /// <param name="priority"></param>
166
194
  /// <returns>The deregistration action. Should be invoked when the handler no longer wants to receive messages.</returns>
167
195
  Action RegisterSourcedBroadcastWithoutSource<T>(
168
196
  MessageHandler messageHandler,