com.wallstop-studios.dxmessaging 2.1.1 → 2.1.2
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/dotnet-tests.yml +72 -0
- package/.lychee.toml +4 -2
- package/AGENTS.md +1 -0
- package/Docs/Comparisons.md +4 -4
- package/Docs/Install.md +2 -1
- package/Docs/Performance.md +13 -11
- package/Editor/Analyzers/Microsoft.CodeAnalysis.CSharp.dll +0 -0
- package/Editor/Analyzers/Microsoft.CodeAnalysis.CSharp.dll.meta +13 -2
- package/Editor/Analyzers/Microsoft.CodeAnalysis.dll +0 -0
- package/Editor/Analyzers/Microsoft.CodeAnalysis.dll.meta +11 -0
- package/Editor/Analyzers/System.Collections.Immutable.dll +0 -0
- package/Editor/Analyzers/System.Collections.Immutable.dll.meta +11 -0
- package/Editor/Analyzers/System.Reflection.Metadata.dll +0 -0
- package/Editor/Analyzers/System.Reflection.Metadata.dll.meta +13 -2
- package/Editor/Analyzers/System.Runtime.CompilerServices.Unsafe.dll +0 -0
- package/Editor/Analyzers/System.Runtime.CompilerServices.Unsafe.dll.meta +11 -0
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll +0 -0
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll.meta +3 -2
- package/Editor/AssemblyInfo.cs +3 -0
- package/Editor/AssemblyInfo.cs.meta +3 -0
- package/Editor/CustomEditors/MessagingComponentEditor.cs +21 -0
- package/Editor/SetupCscRsp.cs +133 -53
- package/Editor/Testing/MessagingComponentEditorHarness.cs +218 -0
- package/Editor/Testing/MessagingComponentEditorHarness.cs.meta +3 -0
- package/Editor/Testing.meta +3 -0
- package/README.md +9 -3
- package/Runtime/AssemblyInfo.cs +1 -0
- package/Runtime/Core/Diagnostics/MessageEmissionData.cs +26 -11
- package/Runtime/Core/Extensions/MessageBusExtensions.cs +2 -2
- package/Runtime/Core/Extensions/MessageExtensions.cs +2 -2
- package/Runtime/Core/InstanceId.cs +5 -3
- package/Runtime/Core/MessageBus/MessageBus.cs +4 -4
- package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs +2 -2
- package/Runtime/Core/MessageBus/MessagingRegistration.cs +3 -3
- package/Runtime/Core/MessageHandler.cs +34 -2
- package/Runtime/Core/MessageRegistrationToken.cs +2 -2
- package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs +2 -0
- package/Runtime/Unity/InitialGlobalMessageBusProvider.cs +2 -0
- package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs +2 -0
- package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs +2 -0
- package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs +2 -0
- package/Runtime/Unity/MessageAwareComponent.cs +2 -0
- package/Runtime/Unity/MessageBusProviderHandle.cs +4 -0
- package/Runtime/Unity/MessagingComponent.cs +16 -0
- package/Runtime/Unity/MessagingComponentInstaller.cs +2 -0
- package/Runtime/Unity/ScriptableMessageBusProvider.cs +2 -0
- package/SourceGenerators/Directory.Build.props +9 -0
- package/SourceGenerators/Directory.Build.props.meta +7 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoConstructorGenerator.cs +19 -24
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxMessageIdGenerator.cs +87 -27
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj +24 -4
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DocsSnippetCompilationTests.cs +193 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DocsSnippetCompilationTests.cs.meta +11 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DxAutoConstructorGeneratorDiagnosticsTests.cs +69 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DxAutoConstructorGeneratorDiagnosticsTests.cs.meta +11 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DxMessageIdGeneratorDiagnosticsTests.cs +66 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DxMessageIdGeneratorDiagnosticsTests.cs.meta +11 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/GeneratorTestUtilities.cs +155 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/GeneratorTestUtilities.cs.meta +11 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/WallstopStudios.DxMessaging.SourceGenerators.Tests.csproj +20 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/WallstopStudios.DxMessaging.SourceGenerators.Tests.csproj.meta +7 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests.meta +8 -0
- package/Tests/Editor/MessagingComponentEditorHarnessTests.cs +243 -0
- package/Tests/Editor/MessagingComponentEditorHarnessTests.cs.meta +3 -0
- package/Tests/Editor/MessagingComponentSerializationTests.cs +129 -0
- package/Tests/Editor/MessagingComponentSerializationTests.cs.meta +3 -0
- package/Tests/Editor/WallstopStudios.DxMessaging.Tests.Editor.asmdef +19 -0
- package/Tests/Editor/WallstopStudios.DxMessaging.Tests.Editor.asmdef.meta +3 -0
- package/Tests/Editor.meta +3 -0
- package/Tests/Runtime/Benchmarks/BenchmarkSession.cs +3 -0
- package/Tests/Runtime/Benchmarks/BenchmarkTestBase.cs +3 -0
- package/Tests/Runtime/Benchmarks/ComparisonPerformanceTests.cs +3 -0
- package/Tests/Runtime/Benchmarks/PerformanceTests.cs +137 -0
- package/Tests/Runtime/Core/AlternateBusTests.cs +3 -0
- package/Tests/Runtime/Core/BroadcastTests.cs +3 -0
- package/Tests/Runtime/Core/CyclicBufferTests.cs +3 -0
- package/Tests/Runtime/Core/DefaultBusFallbackTests.cs +5 -2
- package/Tests/Runtime/Core/DiagnosticsTests.cs +3 -0
- package/Tests/Runtime/Core/EdgeCaseTests.cs +3 -0
- package/Tests/Runtime/Core/EnablementTests.cs +3 -0
- package/Tests/Runtime/Core/Extensions/MessageExtensionsProviderTests.cs +2 -2
- package/Tests/Runtime/Core/GenericMessageTests.cs +3 -0
- package/Tests/Runtime/Core/GlobalAcceptAllTests.cs +3 -0
- package/Tests/Runtime/Core/InterceptorCancellationTests.cs +3 -0
- package/Tests/Runtime/Core/LifecycleTests.cs +3 -0
- package/Tests/Runtime/Core/MessageEmissionDataTests.cs +70 -0
- package/Tests/Runtime/Core/MessageEmissionDataTests.cs.meta +11 -0
- package/Tests/Runtime/Core/MessagingComponentLifecycleTests.cs +3 -0
- package/Tests/Runtime/Core/MessagingTestBase.cs +3 -0
- package/Tests/Runtime/Core/MutationDedupeTests.cs +3 -0
- package/Tests/Runtime/Core/MutationDestructionTests.cs +3 -0
- package/Tests/Runtime/Core/MutationDuringEmissionTests.cs +3 -0
- package/Tests/Runtime/Core/MutationGlobalAddTests.cs +3 -0
- package/Tests/Runtime/Core/MutationInterceptorTests.cs +3 -0
- package/Tests/Runtime/Core/MutationPostProcessorAcrossHandlersTests.cs +3 -0
- package/Tests/Runtime/Core/MutationPostProcessorMoreTests.cs +3 -0
- package/Tests/Runtime/Core/MutationPriorityTests.cs +3 -0
- package/Tests/Runtime/Core/NominalTests.cs +3 -0
- package/Tests/Runtime/Core/OrderingTests.cs +3 -0
- package/Tests/Runtime/Core/OverDeregistrationTests.cs +3 -0
- package/Tests/Runtime/Core/PostProcessorTests.cs +3 -0
- package/Tests/Runtime/Core/ReflexiveErrorTests.cs +3 -0
- package/Tests/Runtime/Core/ReflexiveMessageWarningTests.cs +4 -1
- package/Tests/Runtime/Core/ReflexiveTests.cs +3 -0
- package/Tests/Runtime/Core/RegistrationTests.cs +3 -0
- package/Tests/Runtime/Core/StringShorthandTests.cs +3 -0
- package/Tests/Runtime/Core/TargetedTests.cs +3 -0
- package/Tests/Runtime/Core/TypedShorthandTests.cs +3 -0
- package/Tests/Runtime/Core/UntargetedEquivalenceTests.cs +3 -0
- package/Tests/Runtime/Core/UntargetedPrefreezeTests.cs +14 -78
- package/Tests/Runtime/Core/UntargetedTests.cs +3 -0
- package/Tests/Runtime/Integrations/Reflex/ReflexIntegrationTests.cs +4 -1
- package/Tests/Runtime/Integrations/VContainer/VContainerIntegrationTests.cs +3 -0
- package/Tests/Runtime/Integrations/Zenject/ZenjectIntegrationTests.cs +3 -0
- package/Tests/Runtime/Scripts/Components/GenericMessageAwareComponent.cs +3 -0
- package/Tests/Runtime/Scripts/Components/ManualListenerComponent.cs +3 -0
- package/Tests/Runtime/Scripts/Components/ReflexiveReceiverComponent.cs +3 -0
- package/Tests/Runtime/TestUtilities/UnityFixtureBase.cs +3 -0
- package/Tests/Runtime/Unity/MessageBusProviderAssetTests.cs +3 -0
- package/Tests/Runtime/Unity/MessageBusProviderHandleTests.cs +87 -3
- package/Tests/Runtime/Unity/MessagingComponentInstallerSceneTests.cs +109 -0
- package/Tests/Runtime/Unity/MessagingComponentInstallerSceneTests.cs.meta +11 -0
- package/Tests/Runtime/Unity/MessagingComponentProviderIntegrationTests.cs +159 -17
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj +20 -7
- package/package.json +1 -1
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#if UNITY_EDITOR
|
|
2
|
+
namespace DxMessaging.Editor.Testing
|
|
3
|
+
{
|
|
4
|
+
using System;
|
|
5
|
+
using System.Collections.Generic;
|
|
6
|
+
using System.Linq;
|
|
7
|
+
using Core;
|
|
8
|
+
using Core.Diagnostics;
|
|
9
|
+
using Core.MessageBus;
|
|
10
|
+
using Unity;
|
|
11
|
+
using UnityEngine;
|
|
12
|
+
|
|
13
|
+
/// <summary>
|
|
14
|
+
/// Captures inspector-oriented diagnostics for <see cref="MessagingComponent"/> instances without relying on GUI APIs.
|
|
15
|
+
/// Intended for automated editor tests that need to validate inspector state transitions.
|
|
16
|
+
/// </summary>
|
|
17
|
+
internal static class MessagingComponentEditorHarness
|
|
18
|
+
{
|
|
19
|
+
private static readonly MessageEmissionData[] EmptyEmissions =
|
|
20
|
+
Array.Empty<MessageEmissionData>();
|
|
21
|
+
|
|
22
|
+
internal static MessagingComponentInspectorState Capture(MessagingComponent component)
|
|
23
|
+
{
|
|
24
|
+
if (component == null)
|
|
25
|
+
{
|
|
26
|
+
throw new ArgumentNullException(nameof(component));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
bool globalDiagnosticsEnabled = false;
|
|
30
|
+
IReadOnlyList<MessageEmissionData> globalHistory = EmptyEmissions;
|
|
31
|
+
|
|
32
|
+
if (MessageHandler.MessageBus is MessageBus concreteBus)
|
|
33
|
+
{
|
|
34
|
+
globalDiagnosticsEnabled = concreteBus.DiagnosticsMode;
|
|
35
|
+
if (globalDiagnosticsEnabled && concreteBus._emissionBuffer.Count > 0)
|
|
36
|
+
{
|
|
37
|
+
globalHistory = concreteBus._emissionBuffer.ToArray();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
List<ListenerDiagnosticsView> listenerViews = component
|
|
42
|
+
._registeredListeners.OrderBy(pair => pair.Key.GetInstanceID())
|
|
43
|
+
.Select(pair => CreateListenerView(pair.Key, pair.Value))
|
|
44
|
+
.ToList();
|
|
45
|
+
|
|
46
|
+
ProviderDiagnosticsView providerDiagnostics = CreateProviderDiagnostics(component);
|
|
47
|
+
|
|
48
|
+
return new MessagingComponentInspectorState(
|
|
49
|
+
globalDiagnosticsEnabled,
|
|
50
|
+
globalHistory,
|
|
51
|
+
listenerViews,
|
|
52
|
+
providerDiagnostics
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private static ListenerDiagnosticsView CreateListenerView(
|
|
57
|
+
MonoBehaviour listener,
|
|
58
|
+
MessageRegistrationToken token
|
|
59
|
+
)
|
|
60
|
+
{
|
|
61
|
+
MessageRegistrationView[] registrations = token
|
|
62
|
+
._metadata.OrderBy(pair => pair.Key)
|
|
63
|
+
.Select(pair => new MessageRegistrationView(
|
|
64
|
+
pair.Key,
|
|
65
|
+
pair.Value,
|
|
66
|
+
token._callCounts.TryGetValue(pair.Key, out int callCount) ? callCount : 0
|
|
67
|
+
))
|
|
68
|
+
.ToArray();
|
|
69
|
+
|
|
70
|
+
IReadOnlyList<MessageEmissionData> emissionHistory =
|
|
71
|
+
token._emissionBuffer.Count > 0 ? token._emissionBuffer.ToArray() : EmptyEmissions;
|
|
72
|
+
|
|
73
|
+
return new ListenerDiagnosticsView(
|
|
74
|
+
listener,
|
|
75
|
+
token.DiagnosticMode,
|
|
76
|
+
token.Enabled,
|
|
77
|
+
registrations,
|
|
78
|
+
emissionHistory
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
internal static ProviderDiagnosticsView CreateProviderDiagnostics(
|
|
83
|
+
MessagingComponent component
|
|
84
|
+
)
|
|
85
|
+
{
|
|
86
|
+
bool autoConfigure = component.AutoConfigureSerializedProviderOnAwake;
|
|
87
|
+
bool hasSerializedProvider =
|
|
88
|
+
component.SerializedProviderAsset != null || component.HasSerializedProvider;
|
|
89
|
+
bool hasRuntimeProvider = component.HasRuntimeProvider;
|
|
90
|
+
bool hasMessageBusOverride = component.HasMessageBusOverride;
|
|
91
|
+
bool serializedProviderMissingWarning = autoConfigure && !hasSerializedProvider;
|
|
92
|
+
|
|
93
|
+
bool serializedProviderNullBusWarning = false;
|
|
94
|
+
if (hasSerializedProvider)
|
|
95
|
+
{
|
|
96
|
+
IMessageBus resolvedBus = component.SerializedProviderHandle.ResolveBus();
|
|
97
|
+
serializedProviderNullBusWarning = resolvedBus == null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return new ProviderDiagnosticsView(
|
|
101
|
+
autoConfigure,
|
|
102
|
+
hasSerializedProvider,
|
|
103
|
+
hasRuntimeProvider,
|
|
104
|
+
hasMessageBusOverride,
|
|
105
|
+
serializedProviderMissingWarning,
|
|
106
|
+
serializedProviderNullBusWarning
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
internal sealed class MessagingComponentInspectorState
|
|
112
|
+
{
|
|
113
|
+
internal MessagingComponentInspectorState(
|
|
114
|
+
bool globalDiagnosticsEnabled,
|
|
115
|
+
IReadOnlyList<MessageEmissionData> globalEmissionHistory,
|
|
116
|
+
IReadOnlyList<ListenerDiagnosticsView> listeners,
|
|
117
|
+
ProviderDiagnosticsView providerDiagnostics
|
|
118
|
+
)
|
|
119
|
+
{
|
|
120
|
+
GlobalDiagnosticsEnabled = globalDiagnosticsEnabled;
|
|
121
|
+
GlobalEmissionHistory =
|
|
122
|
+
globalEmissionHistory
|
|
123
|
+
?? throw new ArgumentNullException(nameof(globalEmissionHistory));
|
|
124
|
+
Listeners = listeners ?? throw new ArgumentNullException(nameof(listeners));
|
|
125
|
+
ProviderDiagnostics = providerDiagnostics;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
internal bool GlobalDiagnosticsEnabled { get; }
|
|
129
|
+
|
|
130
|
+
internal IReadOnlyList<MessageEmissionData> GlobalEmissionHistory { get; }
|
|
131
|
+
|
|
132
|
+
internal IReadOnlyList<ListenerDiagnosticsView> Listeners { get; }
|
|
133
|
+
|
|
134
|
+
internal ProviderDiagnosticsView ProviderDiagnostics { get; }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
internal sealed class ListenerDiagnosticsView
|
|
138
|
+
{
|
|
139
|
+
internal ListenerDiagnosticsView(
|
|
140
|
+
MonoBehaviour listener,
|
|
141
|
+
bool diagnosticsEnabled,
|
|
142
|
+
bool tokenEnabled,
|
|
143
|
+
IReadOnlyList<MessageRegistrationView> registrations,
|
|
144
|
+
IReadOnlyList<MessageEmissionData> emissionHistory
|
|
145
|
+
)
|
|
146
|
+
{
|
|
147
|
+
Listener = listener;
|
|
148
|
+
DiagnosticsEnabled = diagnosticsEnabled;
|
|
149
|
+
TokenEnabled = tokenEnabled;
|
|
150
|
+
Registrations = registrations ?? throw new ArgumentNullException(nameof(registrations));
|
|
151
|
+
EmissionHistory =
|
|
152
|
+
emissionHistory ?? throw new ArgumentNullException(nameof(emissionHistory));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
internal MonoBehaviour Listener { get; }
|
|
156
|
+
|
|
157
|
+
internal bool DiagnosticsEnabled { get; }
|
|
158
|
+
|
|
159
|
+
internal bool TokenEnabled { get; }
|
|
160
|
+
|
|
161
|
+
internal IReadOnlyList<MessageRegistrationView> Registrations { get; }
|
|
162
|
+
|
|
163
|
+
internal IReadOnlyList<MessageEmissionData> EmissionHistory { get; }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
internal readonly struct MessageRegistrationView
|
|
167
|
+
{
|
|
168
|
+
internal MessageRegistrationView(
|
|
169
|
+
MessageRegistrationHandle handle,
|
|
170
|
+
MessageRegistrationMetadata metadata,
|
|
171
|
+
int callCount
|
|
172
|
+
)
|
|
173
|
+
{
|
|
174
|
+
Handle = handle;
|
|
175
|
+
Metadata = metadata;
|
|
176
|
+
CallCount = callCount;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
internal MessageRegistrationHandle Handle { get; }
|
|
180
|
+
|
|
181
|
+
internal MessageRegistrationMetadata Metadata { get; }
|
|
182
|
+
|
|
183
|
+
internal int CallCount { get; }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
internal readonly struct ProviderDiagnosticsView
|
|
187
|
+
{
|
|
188
|
+
internal ProviderDiagnosticsView(
|
|
189
|
+
bool autoConfigureSerializedProviderOnAwake,
|
|
190
|
+
bool hasSerializedProvider,
|
|
191
|
+
bool hasRuntimeProvider,
|
|
192
|
+
bool hasMessageBusOverride,
|
|
193
|
+
bool serializedProviderMissingWarning,
|
|
194
|
+
bool serializedProviderNullBusWarning
|
|
195
|
+
)
|
|
196
|
+
{
|
|
197
|
+
AutoConfigureSerializedProviderOnAwake = autoConfigureSerializedProviderOnAwake;
|
|
198
|
+
HasSerializedProvider = hasSerializedProvider;
|
|
199
|
+
HasRuntimeProvider = hasRuntimeProvider;
|
|
200
|
+
HasMessageBusOverride = hasMessageBusOverride;
|
|
201
|
+
SerializedProviderMissingWarning = serializedProviderMissingWarning;
|
|
202
|
+
SerializedProviderNullBusWarning = serializedProviderNullBusWarning;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
internal bool AutoConfigureSerializedProviderOnAwake { get; }
|
|
206
|
+
|
|
207
|
+
internal bool HasSerializedProvider { get; }
|
|
208
|
+
|
|
209
|
+
internal bool HasRuntimeProvider { get; }
|
|
210
|
+
|
|
211
|
+
internal bool HasMessageBusOverride { get; }
|
|
212
|
+
|
|
213
|
+
internal bool SerializedProviderMissingWarning { get; }
|
|
214
|
+
|
|
215
|
+
internal bool SerializedProviderNullBusWarning { get; }
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
#endif
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://unity.com/releases/editor)<br/>
|
|
4
4
|
[](LICENSE.md)<br/>
|
|
5
|
-
[](https://www.npmjs.com/package/com.wallstop-studios.dxmessaging)<br/>
|
|
6
6
|
[](Docs/Performance.md)<br/>
|
|
7
7
|
[](https://github.com/wallstop/DxMessaging/actions/workflows/markdown-link-validity.yml)<br/>
|
|
8
8
|
[](https://github.com/wallstop/DxMessaging/actions/workflows/markdown-link-text-check.yml)
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
Think of it as **the event system Unity should have built-in** — one that actually scales.
|
|
13
13
|
|
|
14
|
+
Need install instructions for Git URLs, scoped registries, or tarballs? Jump to the [Install Guide](Docs/Install.md).
|
|
15
|
+
|
|
14
16
|
## Table of Contents
|
|
15
17
|
|
|
16
18
|
- [30-Second Elevator Pitch](#30-second-elevator-pitch)
|
|
@@ -62,12 +64,15 @@ Think of it as **the event system Unity should have built-in** — one that actu
|
|
|
62
64
|
|
|
63
65
|
### 1. Install
|
|
64
66
|
|
|
65
|
-
Via Unity Package Manager → Add package from git URL:
|
|
67
|
+
Via Unity Package Manager → Add package from git URL (see the [Install Guide](Docs/Install.md) for scoped registry, tarball, and offline options):
|
|
66
68
|
|
|
67
|
-
```
|
|
69
|
+
```bash
|
|
70
|
+
# Unity Package Manager > Add package from git URL...
|
|
68
71
|
https://github.com/wallstop/DxMessaging.git
|
|
69
72
|
```
|
|
70
73
|
|
|
74
|
+
Prefer OpenUPM, scoped registries, or local tarballs? The [Install Guide](Docs/Install.md) covers every path in detail.
|
|
75
|
+
|
|
71
76
|
### 2. Define Your First Message
|
|
72
77
|
|
|
73
78
|
```csharp
|
|
@@ -632,6 +637,7 @@ See [full comparison](Docs/Comparisons.md) for detailed analysis with code examp
|
|
|
632
637
|
|
|
633
638
|
### 📖 Reference
|
|
634
639
|
|
|
640
|
+
- [Install Guide](Docs/Install.md) — All install options (Git URL, scoped registry, tarball, manual copy)
|
|
635
641
|
- [Glossary](Docs/Glossary.md) — All terms explained in plain English
|
|
636
642
|
- [Quick Reference](Docs/QuickReference.md) — Cheat sheet
|
|
637
643
|
- [API Reference](Docs/Reference.md) — Complete API
|
package/Runtime/AssemblyInfo.cs
CHANGED
|
@@ -9,3 +9,4 @@ using System.Runtime.CompilerServices;
|
|
|
9
9
|
[assembly: InternalsVisibleTo("WallstopStudios.DxMessaging.Tests.Runtime.Reflex")]
|
|
10
10
|
[assembly: InternalsVisibleTo("WallstopStudios.DxMessaging.Tests.Runtime.VContainer")]
|
|
11
11
|
[assembly: InternalsVisibleTo("WallstopStudios.DxMessaging.Tests.Runtime.Zenject")]
|
|
12
|
+
[assembly: InternalsVisibleTo("WallstopStudios.DxMessaging.Tests.Editor")]
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
namespace DxMessaging.Core.Diagnostics
|
|
2
2
|
{
|
|
3
3
|
using System;
|
|
4
|
-
|
|
4
|
+
using System.Linq;
|
|
5
|
+
#if UNITY_2021_3_OR_NEWER
|
|
5
6
|
using UnityEngine;
|
|
7
|
+
#else
|
|
8
|
+
using System.Diagnostics;
|
|
6
9
|
#endif
|
|
7
10
|
|
|
8
11
|
/// <summary>
|
|
@@ -45,7 +48,7 @@ namespace DxMessaging.Core.Diagnostics
|
|
|
45
48
|
private static string GetAccurateStackTrace()
|
|
46
49
|
{
|
|
47
50
|
string fullStackTrace;
|
|
48
|
-
#if
|
|
51
|
+
#if UNITY_2021_3_OR_NEWER
|
|
49
52
|
fullStackTrace = StackTraceUtility.ExtractStackTrace();
|
|
50
53
|
#else
|
|
51
54
|
fullStackTrace = new StackTrace(true).ToString();
|
|
@@ -57,18 +60,30 @@ namespace DxMessaging.Core.Diagnostics
|
|
|
57
60
|
|
|
58
61
|
string[] lines = fullStackTrace.Split(NewlineSeparators, StringSplitOptions.None);
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
string[] trimmedLines = lines
|
|
64
|
+
.Where(line => !string.IsNullOrWhiteSpace(line) && !IsInternalFrame(line))
|
|
65
|
+
.ToArray();
|
|
66
|
+
|
|
67
|
+
return trimmedLines.Length == 0
|
|
68
|
+
? string.Empty
|
|
69
|
+
: string.Join(JoinSeparator, trimmedLines);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private static bool IsInternalFrame(string line)
|
|
73
|
+
{
|
|
74
|
+
if (string.IsNullOrWhiteSpace(line))
|
|
65
75
|
{
|
|
66
|
-
|
|
76
|
+
return false;
|
|
67
77
|
}
|
|
68
78
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
79
|
+
if (!line.Contains("DxMessaging.", StringComparison.Ordinal))
|
|
80
|
+
{
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return line.Contains("DxMessaging.Core.", StringComparison.Ordinal)
|
|
85
|
+
|| line.Contains("DxMessaging.Unity.", StringComparison.Ordinal)
|
|
86
|
+
|| line.Contains("DxMessaging.Editor.", StringComparison.Ordinal);
|
|
72
87
|
}
|
|
73
88
|
}
|
|
74
89
|
}
|
|
@@ -4,7 +4,7 @@ namespace DxMessaging.Core.Extensions
|
|
|
4
4
|
using DxMessaging.Core;
|
|
5
5
|
using DxMessaging.Core.MessageBus;
|
|
6
6
|
using DxMessaging.Core.Messages;
|
|
7
|
-
#if
|
|
7
|
+
#if UNITY_2021_3_OR_NEWER
|
|
8
8
|
using UnityEngine;
|
|
9
9
|
#endif
|
|
10
10
|
|
|
@@ -98,7 +98,7 @@ namespace DxMessaging.Core.Extensions
|
|
|
98
98
|
message.EmitBroadcast(source, messageBus);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
#if
|
|
101
|
+
#if UNITY_2021_3_OR_NEWER
|
|
102
102
|
public static void EmitGameObjectTargeted<TMessage>(
|
|
103
103
|
this IMessageBus messageBus,
|
|
104
104
|
GameObject target,
|
|
@@ -37,7 +37,7 @@ namespace DxMessaging.Core.Extensions
|
|
|
37
37
|
/// </example>
|
|
38
38
|
public static class MessageExtensions
|
|
39
39
|
{
|
|
40
|
-
#if
|
|
40
|
+
#if UNITY_2021_3_OR_NEWER
|
|
41
41
|
/// <summary>
|
|
42
42
|
/// Emits a TargetedMessage of the given type.
|
|
43
43
|
/// </summary>
|
|
@@ -395,7 +395,7 @@ namespace DxMessaging.Core.Extensions
|
|
|
395
395
|
resolvedBus.SourcedBroadcast(ref source, ref message);
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
-
#if
|
|
398
|
+
#if UNITY_2021_3_OR_NEWER
|
|
399
399
|
/// <summary>
|
|
400
400
|
/// Emits a BroadcastMessage of the given type.
|
|
401
401
|
/// </summary>
|
|
@@ -30,7 +30,7 @@ namespace DxMessaging.Core
|
|
|
30
30
|
|
|
31
31
|
private readonly int _id;
|
|
32
32
|
|
|
33
|
-
#if
|
|
33
|
+
#if UNITY_2021_3_OR_NEWER
|
|
34
34
|
// ReSharper disable once InconsistentNaming
|
|
35
35
|
public readonly UnityEngine.Object Object;
|
|
36
36
|
#endif
|
|
@@ -38,10 +38,12 @@ namespace DxMessaging.Core
|
|
|
38
38
|
public InstanceId(int id)
|
|
39
39
|
{
|
|
40
40
|
_id = id;
|
|
41
|
+
#if UNITY_2021_3_OR_NEWER
|
|
41
42
|
Object = null;
|
|
43
|
+
#endif
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
#if
|
|
46
|
+
#if UNITY_2021_3_OR_NEWER
|
|
45
47
|
private InstanceId(UnityEngine.Object unityObject)
|
|
46
48
|
{
|
|
47
49
|
_id = unityObject.GetInstanceID();
|
|
@@ -81,7 +83,7 @@ namespace DxMessaging.Core
|
|
|
81
83
|
|
|
82
84
|
public override string ToString()
|
|
83
85
|
{
|
|
84
|
-
#if
|
|
86
|
+
#if UNITY_2021_3_OR_NEWER
|
|
85
87
|
UnityEngine.Object instance = Object;
|
|
86
88
|
string objectName = instance == null ? string.Empty : instance.name;
|
|
87
89
|
return new { Id = _id, Name = objectName }.ToString();
|
|
@@ -12,7 +12,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
12
12
|
using Helper;
|
|
13
13
|
using Messages;
|
|
14
14
|
using static IMessageBus;
|
|
15
|
-
#if
|
|
15
|
+
#if UNITY_2021_3_OR_NEWER
|
|
16
16
|
using UnityEngine;
|
|
17
17
|
#endif
|
|
18
18
|
|
|
@@ -167,7 +167,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
167
167
|
Dictionary<MethodSignatureKey, Action<MonoBehaviour, object[]>>
|
|
168
168
|
> _methodCache = new();
|
|
169
169
|
|
|
170
|
-
#if
|
|
170
|
+
#if UNITY_2021_3_OR_NEWER
|
|
171
171
|
private readonly HashSet<MonoBehaviour> _recipientCache = new();
|
|
172
172
|
private readonly List<MonoBehaviour> _componentCache = new();
|
|
173
173
|
#endif
|
|
@@ -1144,7 +1144,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
1144
1144
|
);
|
|
1145
1145
|
}
|
|
1146
1146
|
}
|
|
1147
|
-
#if
|
|
1147
|
+
#if UNITY_2021_3_OR_NEWER
|
|
1148
1148
|
ref ReflexiveMessage reflexiveMessage = ref Unsafe.As<TMessage, ReflexiveMessage>(
|
|
1149
1149
|
ref typedMessage
|
|
1150
1150
|
);
|
|
@@ -4152,7 +4152,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
4152
4152
|
}
|
|
4153
4153
|
}
|
|
4154
4154
|
|
|
4155
|
-
#if
|
|
4155
|
+
#if UNITY_2021_3_OR_NEWER
|
|
4156
4156
|
private static Action<MonoBehaviour, object[]> CompileMethodAction(MethodInfo methodInfo)
|
|
4157
4157
|
{
|
|
4158
4158
|
ParameterExpression componentParameter = Expression.Parameter(
|
|
@@ -41,7 +41,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
41
41
|
/// </summary>
|
|
42
42
|
public InstanceId? Owner { get; set; }
|
|
43
43
|
|
|
44
|
-
#if
|
|
44
|
+
#if UNITY_2021_3_OR_NEWER
|
|
45
45
|
/// <summary>
|
|
46
46
|
/// Unity object to treat as the owner. Overrides <see cref="Owner"/> when supplied.
|
|
47
47
|
/// </summary>
|
|
@@ -314,7 +314,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
314
314
|
|
|
315
315
|
private static InstanceId ResolveOwner(MessageRegistrationBuildOptions options)
|
|
316
316
|
{
|
|
317
|
-
#if
|
|
317
|
+
#if UNITY_2021_3_OR_NEWER
|
|
318
318
|
if (options.UnityOwner != null)
|
|
319
319
|
{
|
|
320
320
|
if (options.UnityOwner is UnityEngine.GameObject gameObject)
|
|
@@ -58,7 +58,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
58
58
|
/// </summary>
|
|
59
59
|
public readonly RegistrationMethod registrationMethod;
|
|
60
60
|
|
|
61
|
-
#if
|
|
61
|
+
#if UNITY_2021_3_OR_NEWER
|
|
62
62
|
/// <summary>
|
|
63
63
|
/// Unity time of the registration
|
|
64
64
|
/// </summary>
|
|
@@ -83,7 +83,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
83
83
|
this.type = type;
|
|
84
84
|
this.registrationType = registrationType;
|
|
85
85
|
this.registrationMethod = registrationMethod;
|
|
86
|
-
#if
|
|
86
|
+
#if UNITY_2021_3_OR_NEWER
|
|
87
87
|
time = UnityEngine.Time.time;
|
|
88
88
|
#endif
|
|
89
89
|
}
|
|
@@ -92,7 +92,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
92
92
|
{
|
|
93
93
|
return new
|
|
94
94
|
{
|
|
95
|
-
#if
|
|
95
|
+
#if UNITY_2021_3_OR_NEWER
|
|
96
96
|
time,
|
|
97
97
|
#endif
|
|
98
98
|
id,
|
|
@@ -502,7 +502,7 @@ namespace DxMessaging.Core
|
|
|
502
502
|
/// <note>
|
|
503
503
|
/// Ideally, this would be something like a Dictionary[T, Handler[T]], but that can't be done with C#s type system.
|
|
504
504
|
/// </note>
|
|
505
|
-
|
|
505
|
+
internal readonly List<MessageCache<object>> _handlersByTypeByMessageBus;
|
|
506
506
|
private IMessageBus _defaultMessageBus;
|
|
507
507
|
|
|
508
508
|
/// <summary>
|
|
@@ -1934,6 +1934,33 @@ namespace DxMessaging.Core
|
|
|
1934
1934
|
return false;
|
|
1935
1935
|
}
|
|
1936
1936
|
|
|
1937
|
+
internal int GetUntargetedPostProcessingPrefreezeCount<T>(
|
|
1938
|
+
IMessageBus messageBus,
|
|
1939
|
+
int priority
|
|
1940
|
+
)
|
|
1941
|
+
where T : IMessage
|
|
1942
|
+
{
|
|
1943
|
+
if (
|
|
1944
|
+
!GetHandlerForType(messageBus, out TypedHandler<T> handler)
|
|
1945
|
+
|| handler._untargetedPostProcessingFastHandlers == null
|
|
1946
|
+
)
|
|
1947
|
+
{
|
|
1948
|
+
return 0;
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
if (
|
|
1952
|
+
handler._untargetedPostProcessingFastHandlers.TryGetValue(
|
|
1953
|
+
priority,
|
|
1954
|
+
out HandlerActionCache<FastHandler<T>> cache
|
|
1955
|
+
)
|
|
1956
|
+
)
|
|
1957
|
+
{
|
|
1958
|
+
return cache.prefreezeInvocationCount;
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
return 0;
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1937
1964
|
private sealed class HandlerActionCache<T>
|
|
1938
1965
|
{
|
|
1939
1966
|
internal readonly struct Entry
|
|
@@ -3673,7 +3700,12 @@ namespace DxMessaging.Core
|
|
|
3673
3700
|
{
|
|
3674
3701
|
List<TU> list = actionCache.cache;
|
|
3675
3702
|
list.Clear();
|
|
3676
|
-
foreach (
|
|
3703
|
+
foreach (
|
|
3704
|
+
KeyValuePair<
|
|
3705
|
+
TU,
|
|
3706
|
+
HandlerActionCache<TU>.Entry
|
|
3707
|
+
> kvp in actionCache.entries
|
|
3708
|
+
)
|
|
3677
3709
|
{
|
|
3678
3710
|
list.Add(kvp.Value.handler);
|
|
3679
3711
|
}
|
|
@@ -166,7 +166,7 @@ namespace DxMessaging.Core
|
|
|
166
166
|
);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
#if
|
|
169
|
+
#if UNITY_2021_3_OR_NEWER
|
|
170
170
|
/// <summary>
|
|
171
171
|
/// Stages a registration to accept targeted messages of type <typeparamref name="T"/> directed at the given GameObject.
|
|
172
172
|
/// </summary>
|
|
@@ -1024,7 +1024,7 @@ namespace DxMessaging.Core
|
|
|
1024
1024
|
);
|
|
1025
1025
|
}
|
|
1026
1026
|
|
|
1027
|
-
#if
|
|
1027
|
+
#if UNITY_2021_3_OR_NEWER
|
|
1028
1028
|
/// <summary>
|
|
1029
1029
|
/// Stages a registration to accept broadcast messages of type <typeparamref name="T"/> from a given source.
|
|
1030
1030
|
/// </summary>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#if UNITY_2021_3_OR_NEWER
|
|
1
2
|
namespace DxMessaging.Unity
|
|
2
3
|
{
|
|
3
4
|
using System;
|
|
@@ -18,6 +19,8 @@ namespace DxMessaging.Unity
|
|
|
18
19
|
[NonSerialized]
|
|
19
20
|
private IMessageBusProvider _runtimeProvider;
|
|
20
21
|
|
|
22
|
+
internal ScriptableMessageBusProvider SerializedProvider => _provider;
|
|
23
|
+
|
|
21
24
|
/// <summary>
|
|
22
25
|
/// Initializes a new instance referencing the supplied provider asset.
|
|
23
26
|
/// </summary>
|
|
@@ -95,3 +98,4 @@ namespace DxMessaging.Unity
|
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
}
|
|
101
|
+
#endif
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#if UNITY_2021_3_OR_NEWER
|
|
1
2
|
namespace DxMessaging.Unity
|
|
2
3
|
{
|
|
3
4
|
using System;
|
|
@@ -44,6 +45,20 @@ namespace DxMessaging.Unity
|
|
|
44
45
|
internal readonly Dictionary<MonoBehaviour, MessageRegistrationToken> _registeredListeners =
|
|
45
46
|
new();
|
|
46
47
|
|
|
48
|
+
internal bool AutoConfigureSerializedProviderOnAwake =>
|
|
49
|
+
autoConfigureSerializedProviderOnAwake;
|
|
50
|
+
|
|
51
|
+
internal bool HasRuntimeProvider => _messageBusProvider != null;
|
|
52
|
+
|
|
53
|
+
internal bool HasMessageBusOverride => _messageBusOverride != null;
|
|
54
|
+
|
|
55
|
+
internal bool HasSerializedProvider => _serializedProviderHandle.TryGetProvider(out _);
|
|
56
|
+
|
|
57
|
+
internal MessageBusProviderHandle SerializedProviderHandle => _serializedProviderHandle;
|
|
58
|
+
|
|
59
|
+
internal ScriptableMessageBusProvider SerializedProviderAsset =>
|
|
60
|
+
_serializedProviderHandle.SerializedProvider;
|
|
61
|
+
|
|
47
62
|
/// <summary>
|
|
48
63
|
/// Creates a <see cref="IMessageRegistrationBuilder"/> aligned with this component's configured bus or provider.
|
|
49
64
|
/// </summary>
|
|
@@ -313,3 +328,4 @@ namespace DxMessaging.Unity
|
|
|
313
328
|
}
|
|
314
329
|
}
|
|
315
330
|
}
|
|
331
|
+
#endif
|