com.wallstop-studios.dxmessaging 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/format-on-demand.yml +2 -2
- package/.github/workflows/json-format-check.yml +1 -1
- package/.github/workflows/markdown-json.yml +1 -1
- package/.github/workflows/markdownlint.yml +1 -1
- package/.github/workflows/npm-publish.yml +1 -1
- package/.github/workflows/prettier-autofix.yml +2 -2
- package/.github/workflows/yaml-format-lint.yml +1 -1
- package/Docs/Advanced.md +26 -1
- package/Docs/Comparisons.md +1229 -146
- package/Docs/Compatibility.md +27 -0
- package/Docs/DesignAndArchitecture.md +41 -34
- package/Docs/EmitShorthands.md +34 -0
- package/Docs/Helpers.md +1 -1
- package/Docs/Index.md +28 -25
- package/Docs/Install.md +29 -6
- package/Docs/Integrations/Reflex.md +292 -0
- package/Docs/Integrations/Reflex.md.meta +7 -0
- package/Docs/Integrations/VContainer.md +324 -0
- package/Docs/Integrations/VContainer.md.meta +7 -0
- package/Docs/Integrations/Zenject.md +333 -0
- package/Docs/Integrations/Zenject.md.meta +7 -0
- package/{Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.pdb.meta → Docs/Integrations.meta} +2 -1
- package/Docs/InterceptorsAndOrdering.md +371 -17
- package/Docs/ListeningPatterns.md +206 -0
- package/Docs/MessageBusProviders.md +496 -0
- package/Docs/MessageBusProviders.md.meta +7 -0
- package/Docs/MessageTypes.md +27 -0
- package/Docs/MigrationGuide.md +45 -0
- package/Docs/Patterns.md +286 -0
- package/Docs/Performance.md +9 -9
- package/Docs/QuickReference.md +31 -0
- package/Docs/RuntimeConfiguration.md +407 -0
- package/Docs/RuntimeConfiguration.md.meta +7 -0
- package/Docs/UnityIntegration.md +3 -1
- package/Docs/VisualGuide.md +206 -157
- package/Editor/CustomEditors/MessagingComponentEditor.cs +15 -6
- package/README.md +148 -26
- package/Runtime/AssemblyInfo.cs +4 -0
- package/Runtime/Core/Extensions/MessageBusExtensions.cs +253 -0
- package/Runtime/Core/Extensions/MessageBusExtensions.cs.meta +12 -0
- package/Runtime/Core/Extensions/MessageExtensions.cs +137 -89
- package/Runtime/Core/MessageBus/GlobalMessageBusProvider.cs +23 -0
- package/Runtime/Core/MessageBus/GlobalMessageBusProvider.cs.meta +11 -0
- package/Runtime/Core/MessageBus/IMessageBusProvider.cs +14 -0
- package/Runtime/Core/MessageBus/IMessageBusProvider.cs.meta +11 -0
- package/Runtime/Core/MessageBus/IMessageRegistrationBuilder.cs +18 -0
- package/Runtime/Core/MessageBus/IMessageRegistrationBuilder.cs.meta +11 -0
- package/Runtime/Core/MessageBus/MessageBusRebindMode.cs +26 -0
- package/Runtime/Core/MessageBus/MessageBusRebindMode.cs.meta +11 -0
- package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs +383 -0
- package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs.meta +11 -0
- package/Runtime/Core/MessageHandler.cs +198 -27
- package/Runtime/Core/MessageRegistrationToken.cs +67 -25
- package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs +31 -0
- package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs.meta +12 -0
- package/Runtime/Unity/InitialGlobalMessageBusProvider.cs +38 -0
- package/Runtime/Unity/InitialGlobalMessageBusProvider.cs.meta +12 -0
- package/Runtime/Unity/Integrations/Reflex/AssemblyInfo.cs +11 -0
- package/Runtime/Unity/Integrations/Reflex/AssemblyInfo.cs.meta +3 -0
- package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs +73 -0
- package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs.meta +11 -0
- package/Runtime/Unity/Integrations/Reflex/WallstopStudios.DxMessaging.Reflex.asmdef +20 -0
- package/Runtime/Unity/Integrations/Reflex/WallstopStudios.DxMessaging.Reflex.asmdef.meta +7 -0
- package/Runtime/Unity/Integrations/Reflex.meta +8 -0
- package/Runtime/Unity/Integrations/VContainer/AssemblyInfo.cs +11 -0
- package/Runtime/Unity/Integrations/VContainer/AssemblyInfo.cs.meta +3 -0
- package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs +46 -0
- package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs.meta +11 -0
- package/Runtime/Unity/Integrations/VContainer/WallstopStudios.DxMessaging.VContainer.asmdef +30 -0
- package/Runtime/Unity/Integrations/VContainer/WallstopStudios.DxMessaging.VContainer.asmdef.meta +7 -0
- package/Runtime/Unity/Integrations/VContainer.meta +8 -0
- package/Runtime/Unity/Integrations/Zenject/AssemblyInfo.cs +11 -0
- package/Runtime/Unity/Integrations/Zenject/AssemblyInfo.cs.meta +3 -0
- package/Runtime/Unity/Integrations/Zenject/WallstopStudios.DxMessaging.Zenject.asmdef +30 -0
- package/Runtime/Unity/Integrations/Zenject/WallstopStudios.DxMessaging.Zenject.asmdef.meta +7 -0
- package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs +55 -0
- package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs.meta +11 -0
- package/Runtime/Unity/Integrations/Zenject.meta +8 -0
- package/Runtime/Unity/Integrations.meta +8 -0
- package/Runtime/Unity/MessageAwareComponent.cs +102 -0
- package/Runtime/Unity/MessageBusProviderHandle.cs +97 -0
- package/Runtime/Unity/MessageBusProviderHandle.cs.meta +12 -0
- package/Runtime/Unity/MessagingComponent.cs +164 -2
- package/Runtime/Unity/MessagingComponentInstaller.cs +120 -0
- package/Runtime/Unity/MessagingComponentInstaller.cs.meta +12 -0
- package/Runtime/Unity/ScriptableMessageBusProvider.cs +14 -0
- package/Runtime/Unity/ScriptableMessageBusProvider.cs.meta +12 -0
- package/Samples~/DI/Prefabs/MessagingInstallerSample.prefab +98 -0
- package/Samples~/DI/Prefabs/MessagingInstallerSample.prefab.meta +7 -0
- package/Samples~/DI/Prefabs.meta +8 -0
- package/Samples~/DI/Providers/GlobalMessageBusProvider.asset +14 -0
- package/Samples~/DI/Providers/GlobalMessageBusProvider.asset.meta +8 -0
- package/Samples~/DI/Providers/InitialGlobalMessageBusProvider.asset +14 -0
- package/Samples~/DI/Providers/InitialGlobalMessageBusProvider.asset.meta +8 -0
- package/Samples~/DI/Providers.meta +8 -0
- package/Samples~/DI/README.md +51 -0
- package/Samples~/DI/README.md.meta +7 -0
- package/Samples~/DI/Reflex/SampleInstaller.cs +75 -0
- package/Samples~/DI/Reflex/SampleInstaller.cs.meta +11 -0
- package/Samples~/DI/Reflex.meta +8 -0
- package/Samples~/DI/VContainer/SampleLifetimeScope.cs +81 -0
- package/Samples~/DI/VContainer/SampleLifetimeScope.cs.meta +11 -0
- package/Samples~/DI/VContainer.meta +8 -0
- package/Samples~/DI/Zenject/SampleInstaller.cs +67 -0
- package/Samples~/DI/Zenject/SampleInstaller.cs.meta +11 -0
- package/Samples~/DI/Zenject.meta +8 -0
- package/Samples~/DI.meta +8 -0
- package/Samples~/Mini Combat/README.md +5 -7
- package/Samples~/Mini Combat/Walkthrough.md +18 -24
- package/Samples~/UI Buttons + Inspector/DiagnosticsEnabler.cs +12 -2
- package/Samples~/UI Buttons + Inspector/README.md.meta +7 -0
- package/Tests/Runtime/Benchmarks/BenchmarkSession.cs +444 -0
- package/Tests/Runtime/Benchmarks/BenchmarkSession.cs.meta +11 -0
- package/Tests/Runtime/Benchmarks/BenchmarkTestBase.cs +94 -0
- package/Tests/Runtime/Benchmarks/BenchmarkTestBase.cs.meta +11 -0
- package/Tests/Runtime/Benchmarks/ComparisonPerformanceTests.cs +395 -0
- package/Tests/Runtime/Benchmarks/ComparisonPerformanceTests.cs.meta +11 -0
- package/Tests/Runtime/Benchmarks/PerformanceTests.cs +77 -429
- package/Tests/Runtime/Benchmarks/ProviderResolutionBenchmarks.cs +142 -0
- package/Tests/Runtime/Benchmarks/ProviderResolutionBenchmarks.cs.meta +12 -0
- package/Tests/Runtime/Benchmarks/WallstopStudios.DxMessaging.Tests.Runtime.Benchmarks.asmdef +50 -0
- package/Tests/Runtime/Benchmarks/WallstopStudios.DxMessaging.Tests.Runtime.Benchmarks.asmdef.meta +7 -0
- package/Tests/Runtime/Core/DefaultBusFallbackTests.cs +333 -0
- package/Tests/Runtime/Core/DefaultBusFallbackTests.cs.meta +11 -0
- package/Tests/Runtime/Core/Extensions/MessageBusExtensionsTests.cs +278 -0
- package/Tests/Runtime/Core/Extensions/MessageBusExtensionsTests.cs.meta +11 -0
- package/Tests/Runtime/Core/Extensions/MessageExtensionsProviderTests.cs +289 -0
- package/Tests/Runtime/Core/Extensions/MessageExtensionsProviderTests.cs.meta +11 -0
- package/Tests/Runtime/Core/Extensions.meta +8 -0
- package/Tests/Runtime/Core/IntegrationShimSmokeTests.cs +57 -0
- package/Tests/Runtime/Core/IntegrationShimSmokeTests.cs.meta +11 -0
- package/Tests/Runtime/Core/MessageHandlerGlobalBusTests.cs +219 -0
- package/Tests/Runtime/Core/MessageHandlerGlobalBusTests.cs.meta +11 -0
- package/Tests/Runtime/Core/MessageRegistrationBuilderTests.cs +204 -0
- package/Tests/Runtime/Core/MessageRegistrationBuilderTests.cs.meta +11 -0
- package/Tests/Runtime/Core/MessagingTestBase.cs +4 -4
- package/Tests/Runtime/Core/NominalTests.cs +2 -2
- package/Tests/Runtime/Core/TypedShorthandTests.cs +2 -2
- package/Tests/Runtime/Core/UntargetedEquivalenceTests.cs +1 -1
- package/Tests/Runtime/Core/UntargetedPrefreezeTests.cs +2 -4
- package/Tests/Runtime/Integrations/Reflex/ReflexIntegrationTests.cs +162 -0
- package/Tests/Runtime/Integrations/Reflex/ReflexIntegrationTests.cs.meta +11 -0
- package/Tests/Runtime/Integrations/Reflex/Resources/ReflexSettings.asset +16 -0
- package/Tests/Runtime/Integrations/Reflex/Resources/ReflexSettings.asset.meta +8 -0
- package/Tests/Runtime/Integrations/Reflex/Resources.meta +8 -0
- package/Tests/Runtime/Integrations/Reflex/WallstopStudios.DxMessaging.Tests.Runtime.Reflex.asmdef +27 -0
- package/Tests/Runtime/Integrations/Reflex/WallstopStudios.DxMessaging.Tests.Runtime.Reflex.asmdef.meta +7 -0
- package/Tests/Runtime/Integrations/Reflex.meta +8 -0
- package/Tests/Runtime/Integrations/VContainer/VContainerIntegrationTests.cs +140 -0
- package/Tests/Runtime/Integrations/VContainer/VContainerIntegrationTests.cs.meta +11 -0
- package/Tests/Runtime/Integrations/VContainer/WallstopStudios.DxMessaging.Tests.Runtime.VContainer.asmdef +37 -0
- package/Tests/Runtime/Integrations/VContainer/WallstopStudios.DxMessaging.Tests.Runtime.VContainer.asmdef.meta +7 -0
- package/Tests/Runtime/Integrations/VContainer.meta +8 -0
- package/Tests/Runtime/Integrations/Zenject/WallstopStudios.DxMessaging.Tests.Runtime.Zenject.asmdef +37 -0
- package/Tests/Runtime/Integrations/Zenject/WallstopStudios.DxMessaging.Tests.Runtime.Zenject.asmdef.meta +7 -0
- package/Tests/Runtime/Integrations/Zenject/ZenjectIntegrationTests.cs +140 -0
- package/Tests/Runtime/Integrations/Zenject/ZenjectIntegrationTests.cs.meta +11 -0
- package/Tests/Runtime/Integrations/Zenject.meta +8 -0
- package/Tests/Runtime/Integrations.meta +8 -0
- package/Tests/Runtime/Scripts/Components/EmptyMessageAwareComponent.cs +1 -1
- package/Tests/Runtime/Scripts/Components/GenericMessageAwareComponent.cs +1 -1
- package/Tests/Runtime/Scripts/Components/SimpleMessageAwareComponent.cs +1 -1
- package/Tests/Runtime/TestUtilities/UnityFixtureBase.cs +64 -0
- package/Tests/Runtime/TestUtilities/UnityFixtureBase.cs.meta +12 -0
- package/Tests/Runtime/TestUtilities.meta +9 -0
- package/Tests/Runtime/Unity/MessageBusProviderAssetTests.cs +57 -0
- package/Tests/Runtime/Unity/MessageBusProviderAssetTests.cs.meta +11 -0
- package/Tests/Runtime/Unity/MessageBusProviderHandleTests.cs +107 -0
- package/Tests/Runtime/Unity/MessageBusProviderHandleTests.cs.meta +12 -0
- package/Tests/Runtime/Unity/MessagingComponentProviderIntegrationTests.cs +210 -0
- package/Tests/Runtime/Unity/MessagingComponentProviderIntegrationTests.cs.meta +12 -0
- package/Tests/Runtime/Unity.meta +9 -0
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.asmdef +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# DxMessaging DI Samples
|
|
2
|
+
|
|
3
|
+
These snippets illustrate how to consume `IMessageRegistrationBuilder` inside common Unity dependency injection containers. The scripts compile only when the corresponding scripting define is enabled and the container package is present.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
1. Install the relevant container package (Zenject/Extenject, VContainer, or Reflex) into your Unity project.
|
|
8
|
+
2. Enable the matching scripting define symbol in **Project Settings › Player › Scripting Define Symbols**:
|
|
9
|
+
- `ZENJECT_PRESENT`
|
|
10
|
+
- `VCONTAINER_PRESENT`
|
|
11
|
+
- `REFLEX_PRESENT`
|
|
12
|
+
3. Import the sample folder you need into your Unity project (`Assets/Samples/DxMessaging/*`).
|
|
13
|
+
|
|
14
|
+
Each sample shows:
|
|
15
|
+
|
|
16
|
+
- Registering `IMessageRegistrationBuilder` via the provided shim under `Runtime/Unity/Integrations/`.
|
|
17
|
+
- Constructing a `MessageRegistrationLease` in a container-managed service.
|
|
18
|
+
- Activating/deactivating the lease using the container lifecycle.
|
|
19
|
+
|
|
20
|
+
### Structure
|
|
21
|
+
|
|
22
|
+
- `Zenject/SampleInstaller.cs`
|
|
23
|
+
- `VContainer/SampleLifetimeScope.cs`
|
|
24
|
+
- `Reflex/SampleInstaller.cs`
|
|
25
|
+
- `Providers/CurrentGlobalMessageBusProvider.asset` — ScriptableObject that resolves whichever bus is currently configured as global.
|
|
26
|
+
- `Providers/InitialGlobalMessageBusProvider.asset` — ScriptableObject that always returns the original startup global bus, ignoring later overrides.
|
|
27
|
+
- `Prefabs/MessagingInstallerSample.prefab` — ready-to-use hierarchy with `MessagingComponentInstaller` configuring a child `MessagingComponent` using the provider asset. Drop it into a scene to see provider-driven wiring without writing setup code.
|
|
28
|
+
|
|
29
|
+
## Walkthrough
|
|
30
|
+
|
|
31
|
+
1. **Place the prefab**
|
|
32
|
+
Drag `Prefabs/MessagingInstallerSample.prefab` into your test scene. The root object carries `MessagingComponentInstaller` with its provider handle already pointing at the global provider ScriptableObject.
|
|
33
|
+
|
|
34
|
+
2. **Hook up the container**
|
|
35
|
+
- **Zenject**:
|
|
36
|
+
- Add `DxMessagingRegistrationInstaller` (from `Runtime/Unity/Integrations/`) to your ProjectContext or scene installer list.
|
|
37
|
+
- Drop `Zenject/SampleInstaller.cs` into your project and register it alongside other installers. When the scene runs, the installer resolves `IMessageRegistrationBuilder`, stages a `PlayerSpawned` listener, and activates via the Zenject lifecycle.
|
|
38
|
+
- **VContainer**:
|
|
39
|
+
- Define `VCONTAINER_PRESENT` and reference the optional extension under `Runtime/Unity/Integrations/VContainerRegistrationExtensions.cs`.
|
|
40
|
+
- Add `VContainer/SampleLifetimeScope` to the scene (or derive from it); the sample scope registers the builder and an entry point that emits/consumes `ScoreUpdated` messages each tick.
|
|
41
|
+
- **Reflex**:
|
|
42
|
+
- Enable `REFLEX_PRESENT` and install `DxMessagingRegistrationInstaller` into your container bootstrap.
|
|
43
|
+
- Include `Reflex/SampleInstaller` in your installer chain. The sample service resolves `IMessageRegistrationBuilder`, subscribes to `PlayerAlert`, and can emit alerts via `EmitAlertFor`.
|
|
44
|
+
|
|
45
|
+
3. **Emit a message**
|
|
46
|
+
Use the service exposed by the container (e.g., call into `ScoreboardService` or `PlayerAlertService`) to emit a message. Because the prefab already configured `MessagingComponent` instances via the installer, the listeners run immediately.
|
|
47
|
+
|
|
48
|
+
4. **Swap providers** (optional)
|
|
49
|
+
Duplicate `Providers/CurrentGlobalMessageBusProvider.asset`, modify it to return a custom bus, assign it on the prefab root, and observe how builder-created leases now resolve that bus instead.
|
|
50
|
+
|
|
51
|
+
Feel free to duplicate these scripts into your own project and adjust lifecycles or message types as needed.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#if REFLEX_PRESENT
|
|
2
|
+
namespace DxMessaging.Samples.DI.Reflex
|
|
3
|
+
{
|
|
4
|
+
using DxMessaging.Core;
|
|
5
|
+
using DxMessaging.Core.MessageBus;
|
|
6
|
+
using DxMessaging.Core.Messages;
|
|
7
|
+
using DxMessaging.Unity.Integrations.Reflex;
|
|
8
|
+
using Reflex.Core;
|
|
9
|
+
using UnityEngine;
|
|
10
|
+
|
|
11
|
+
/// <summary>
|
|
12
|
+
/// Demonstrates wiring <see cref="IMessageRegistrationBuilder"/> inside a Reflex container.
|
|
13
|
+
/// Requires the Reflex package and the REFLEX_PRESENT scripting define.
|
|
14
|
+
/// </summary>
|
|
15
|
+
public sealed class SampleInstaller : Installer
|
|
16
|
+
{
|
|
17
|
+
protected override void InstallBindings()
|
|
18
|
+
{
|
|
19
|
+
Container.Bind<MessageBus>().AsSingleton();
|
|
20
|
+
Container.Bind<IMessageBus>().FromContainer<MessageBus>();
|
|
21
|
+
|
|
22
|
+
// The DxMessagingRegistrationInstaller shim will have been installed elsewhere; we simply resolve the builder.
|
|
23
|
+
Container.Bind<PlayerAlertService>().AsSingleton();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private sealed class PlayerAlertService : System.IDisposable
|
|
27
|
+
{
|
|
28
|
+
private readonly IMessageBus _messageBus;
|
|
29
|
+
private readonly MessageRegistrationLease _lease;
|
|
30
|
+
|
|
31
|
+
public PlayerAlertService(IMessageBus messageBus, IMessageRegistrationBuilder builder)
|
|
32
|
+
{
|
|
33
|
+
_messageBus = messageBus;
|
|
34
|
+
_lease = builder.Build(
|
|
35
|
+
new MessageRegistrationBuildOptions
|
|
36
|
+
{
|
|
37
|
+
Configure = token =>
|
|
38
|
+
{
|
|
39
|
+
_ = token.RegisterBroadcastWithoutSource<PlayerAlert>(OnPlayerAlert);
|
|
40
|
+
},
|
|
41
|
+
HandlerStartsActive = true,
|
|
42
|
+
ActivateOnBuild = true,
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public void EmitAlertFor(GameObject source)
|
|
48
|
+
{
|
|
49
|
+
PlayerAlert alert = new PlayerAlert(source);
|
|
50
|
+
_messageBus.Emit(ref alert);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public void Dispose()
|
|
54
|
+
{
|
|
55
|
+
_lease.Dispose();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private void OnPlayerAlert(ref InstanceId source, ref PlayerAlert alert)
|
|
59
|
+
{
|
|
60
|
+
Debug.Log($"Reflex alert from {source.Id}");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private readonly struct PlayerAlert : IBroadcastMessage
|
|
65
|
+
{
|
|
66
|
+
public PlayerAlert(InstanceId source)
|
|
67
|
+
{
|
|
68
|
+
Source = source;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public InstanceId Source { get; }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
#endif
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#if VCONTAINER_PRESENT
|
|
2
|
+
namespace DxMessaging.Samples.DI.VContainer
|
|
3
|
+
{
|
|
4
|
+
using System;
|
|
5
|
+
using Core.Attributes;
|
|
6
|
+
using Core.Extensions;
|
|
7
|
+
using Core.MessageBus;
|
|
8
|
+
using DxMessaging.Unity.Integrations.VContainer;
|
|
9
|
+
using UnityEngine;
|
|
10
|
+
using VContainer;
|
|
11
|
+
using VContainer.Unity;
|
|
12
|
+
|
|
13
|
+
/// <summary>
|
|
14
|
+
/// Sample lifetime scope showing DI-friendly registration via IMessageRegistrationBuilder.
|
|
15
|
+
/// Requires the VCONTAINER_PRESENT scripting define and VContainer package.
|
|
16
|
+
/// </summary>
|
|
17
|
+
public sealed class SampleLifetimeScope : LifetimeScope
|
|
18
|
+
{
|
|
19
|
+
protected override void Configure(IContainerBuilder builder)
|
|
20
|
+
{
|
|
21
|
+
builder.Register<MessageBus.MessageBus>(Lifetime.Singleton).As<IMessageBus>();
|
|
22
|
+
builder.RegisterMessageRegistrationBuilder();
|
|
23
|
+
|
|
24
|
+
builder.RegisterEntryPoint<ScoreboardService>(Lifetime.Singleton);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
[DxUntargetedMessage]
|
|
28
|
+
private readonly struct ScoreUpdated
|
|
29
|
+
{
|
|
30
|
+
public readonly int Value;
|
|
31
|
+
|
|
32
|
+
public ScoreUpdated(int value)
|
|
33
|
+
{
|
|
34
|
+
Value = value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private sealed class ScoreboardService : IStartable, ITickable, IDisposable
|
|
39
|
+
{
|
|
40
|
+
private readonly MessageRegistrationLease lease;
|
|
41
|
+
private int observedScores;
|
|
42
|
+
|
|
43
|
+
public ScoreboardService(IMessageRegistrationBuilder registrationBuilder)
|
|
44
|
+
{
|
|
45
|
+
lease = registrationBuilder.Build(
|
|
46
|
+
new MessageRegistrationBuildOptions
|
|
47
|
+
{
|
|
48
|
+
Configure = token =>
|
|
49
|
+
{
|
|
50
|
+
_ = token.RegisterUntargeted<ScoreUpdated>(OnScoreUpdated);
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public void Start()
|
|
57
|
+
{
|
|
58
|
+
lease.Activate();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public void Tick()
|
|
62
|
+
{
|
|
63
|
+
// Emit periodically for demo purposes
|
|
64
|
+
ScoreUpdated message = new ScoreUpdated(UnityEngine.Random.Range(0, 100));
|
|
65
|
+
message.Emit();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public void Dispose()
|
|
69
|
+
{
|
|
70
|
+
lease.Dispose();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private void OnScoreUpdated(ref ScoreUpdated message)
|
|
74
|
+
{
|
|
75
|
+
observedScores = message.Value;
|
|
76
|
+
Debug.Log($"Score observed: {observedScores}");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
#endif
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#if ZENJECT_PRESENT
|
|
2
|
+
namespace DxMessaging.Samples.DI.Zenject
|
|
3
|
+
{
|
|
4
|
+
using System;
|
|
5
|
+
using Core.Attributes;
|
|
6
|
+
using Core.MessageBus;
|
|
7
|
+
using UnityEngine;
|
|
8
|
+
using Zenject;
|
|
9
|
+
|
|
10
|
+
/// <summary>
|
|
11
|
+
/// Sample scene installer demonstrating how to bridge the registration builder into Zenject services.
|
|
12
|
+
/// Requires the DxMessaging Zenject registration shim and the ZENJECT_PRESENT scripting define.
|
|
13
|
+
/// </summary>
|
|
14
|
+
public sealed class SampleInstaller : MonoInstaller
|
|
15
|
+
{
|
|
16
|
+
public override void InstallBindings()
|
|
17
|
+
{
|
|
18
|
+
// Ensure the builder is available (provided by DxMessagingRegistrationInstaller).
|
|
19
|
+
Container.BindInterfacesTo<PlayerSpawnTracker>().AsSingle();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
[DxUntargetedMessage]
|
|
23
|
+
private readonly struct PlayerSpawned
|
|
24
|
+
{
|
|
25
|
+
public readonly string PlayerName;
|
|
26
|
+
|
|
27
|
+
public PlayerSpawned(string playerName)
|
|
28
|
+
{
|
|
29
|
+
PlayerName = playerName;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private sealed class PlayerSpawnTracker : IInitializable, IDisposable
|
|
34
|
+
{
|
|
35
|
+
private readonly MessageRegistrationLease lease;
|
|
36
|
+
|
|
37
|
+
public PlayerSpawnTracker(IMessageRegistrationBuilder builder)
|
|
38
|
+
{
|
|
39
|
+
lease = builder.Build(
|
|
40
|
+
new MessageRegistrationBuildOptions
|
|
41
|
+
{
|
|
42
|
+
Configure = token =>
|
|
43
|
+
{
|
|
44
|
+
_ = token.RegisterUntargeted<PlayerSpawned>(OnPlayerSpawned);
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public void Initialize()
|
|
51
|
+
{
|
|
52
|
+
lease.Activate();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public void Dispose()
|
|
56
|
+
{
|
|
57
|
+
lease.Dispose();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private static void OnPlayerSpawned(ref PlayerSpawned message)
|
|
61
|
+
{
|
|
62
|
+
Debug.Log($"Player spawned: {message.PlayerName}");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
#endif
|
package/Samples~/DI.meta
ADDED
|
@@ -147,13 +147,11 @@ Press Play! The Boot script will automatically:
|
|
|
147
147
|
|
|
148
148
|
### The Message Flow
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
└─→ TookDamage (Broadcast from Enemy) → UIOverlay.cs (receives)
|
|
156
|
-
```
|
|
150
|
+
#### Boot.cs sends messages:
|
|
151
|
+
|
|
152
|
+
1. `VideoSettingsChanged` (Untargeted) → UIOverlay.cs receives
|
|
153
|
+
2. `Heal` (Targeted to Player) → Player.cs receives
|
|
154
|
+
3. `TookDamage` (Broadcast from Enemy) → UIOverlay.cs receives
|
|
157
155
|
|
|
158
156
|
### Understanding Message Types
|
|
159
157
|
|
|
@@ -107,30 +107,24 @@ Let's understand what each script does:
|
|
|
107
107
|
|
|
108
108
|
Here's the full sequence that happens when you press Play:
|
|
109
109
|
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
│ STEP 3: Enemy broadcasts TookDamage │
|
|
129
|
-
│ (Broadcast - all listeners receive it) │
|
|
130
|
-
└────────────┬────────────────────────────────────────────────────┘
|
|
131
|
-
│
|
|
132
|
-
├──────────────► UIOverlay receives it
|
|
133
|
-
└─► Shows damage notification
|
|
110
|
+
```mermaid
|
|
111
|
+
sequenceDiagram
|
|
112
|
+
participant Boot
|
|
113
|
+
participant UIOverlay
|
|
114
|
+
participant Player
|
|
115
|
+
participant Enemy
|
|
116
|
+
|
|
117
|
+
Note over Boot: STEP 1: Boot starts
|
|
118
|
+
Boot->>UIOverlay: VideoSettingsChanged (Untargeted)
|
|
119
|
+
Note over UIOverlay: Rebuilds UI
|
|
120
|
+
|
|
121
|
+
Note over Boot: STEP 2: Boot sends Heal
|
|
122
|
+
Boot->>Player: Heal (Targeted)
|
|
123
|
+
Note over Player: Increases HP by heal amount
|
|
124
|
+
|
|
125
|
+
Note over Enemy: STEP 3: Enemy broadcasts
|
|
126
|
+
Enemy->>UIOverlay: TookDamage (Broadcast)
|
|
127
|
+
Note over UIOverlay: Shows damage notification
|
|
134
128
|
```
|
|
135
129
|
|
|
136
130
|
---
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
using DxMessaging.Core;
|
|
2
|
+
using DxMessaging.Core.MessageBus;
|
|
2
3
|
using UnityEngine;
|
|
3
4
|
|
|
4
5
|
public sealed class DiagnosticsEnabler : MonoBehaviour
|
|
@@ -10,8 +11,17 @@ public sealed class DiagnosticsEnabler : MonoBehaviour
|
|
|
10
11
|
{
|
|
11
12
|
if (enableOnStart)
|
|
12
13
|
{
|
|
13
|
-
MessageHandler.MessageBus
|
|
14
|
-
|
|
14
|
+
if (MessageHandler.MessageBus is MessageBus concreteBus)
|
|
15
|
+
{
|
|
16
|
+
concreteBus.DiagnosticsMode = true;
|
|
17
|
+
Debug.Log("DxMessaging global diagnostics enabled.");
|
|
18
|
+
}
|
|
19
|
+
else
|
|
20
|
+
{
|
|
21
|
+
Debug.LogWarning(
|
|
22
|
+
"Global diagnostics are unavailable because the active global bus is not the default DxMessaging implementation."
|
|
23
|
+
);
|
|
24
|
+
}
|
|
15
25
|
}
|
|
16
26
|
}
|
|
17
27
|
}
|