com.wallstop-studios.dxmessaging 2.1.2 → 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.
- package/.github/workflows/dotnet-tests.yml +1 -1
- package/AGENTS.md +12 -12
- package/Docs/Comparisons.md +5 -5
- package/Docs/InterceptorsAndOrdering.md +1 -1
- package/Docs/Performance.md +13 -13
- package/Docs/QuickReference.md +1 -1
- package/Docs/Reference.md +5 -5
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll +0 -0
- package/Editor/CustomEditors/MessagingComponentEditor.cs +3 -0
- package/Editor/DxMessagingEditorInitializer.cs +58 -1
- package/Editor/DxMessagingMenu.cs +38 -0
- package/Editor/DxMessagingMenu.cs.meta +11 -0
- package/Editor/DxMessagingSceneBuildProcessor.cs +81 -0
- package/Editor/DxMessagingSceneBuildProcessor.cs.meta +11 -0
- package/Editor/Settings/DxMessagingSettings.cs +37 -6
- package/Editor/Settings/DxMessagingSettingsProvider.cs +45 -7
- package/README.md +1 -1
- package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs +52 -0
- package/Runtime/Core/DataStructure/CyclicBuffer.cs +16 -0
- package/Runtime/Core/Diagnostics/MessageEmissionData.cs +1 -1
- package/Runtime/Core/Diagnostics/MessageRegistrationType.cs +62 -0
- package/Runtime/Core/DxMessagingStaticState.cs +108 -0
- package/Runtime/Core/DxMessagingStaticState.cs.meta +11 -0
- package/Runtime/Core/Extensions/IListExtensions.cs +24 -0
- package/Runtime/Core/Extensions/MessageBusExtensions.cs +142 -0
- package/Runtime/Core/Helper/MessageCache.cs +16 -0
- package/Runtime/Core/Helper/MessageHelperIndexer.cs +77 -0
- package/Runtime/Core/InstanceId.cs +86 -0
- package/Runtime/Core/MessageBus/DiagnosticsTarget.cs +31 -0
- package/Runtime/Core/MessageBus/DiagnosticsTarget.cs.meta +11 -0
- package/Runtime/Core/MessageBus/IMessageBus.cs +44 -16
- package/Runtime/Core/MessageBus/MessageBus.cs +92 -21
- package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs +44 -0
- package/Runtime/Core/MessageBus/MessagingRegistration.cs +60 -2
- package/Runtime/Core/MessageBus/RegistrationLog.cs +10 -0
- package/Runtime/Core/MessageHandler.cs +107 -6
- package/Runtime/Core/MessageRegistrationHandle.cs +59 -0
- package/Runtime/Core/MessageRegistrationToken.cs +18 -2
- package/Runtime/Core/Messages/ReflexiveMessage.cs +38 -0
- package/Runtime/Core/MessagingDebug.cs +16 -1
- package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs +4 -0
- package/Runtime/Unity/DxMessagingRuntimeInitializer.cs +19 -0
- package/Runtime/Unity/DxMessagingRuntimeInitializer.cs.meta +11 -0
- package/Runtime/Unity/InitialGlobalMessageBusProvider.cs +4 -0
- package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs +17 -0
- package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs +8 -0
- package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs +12 -0
- package/Runtime/Unity/MessagingComponent.cs +93 -0
- package/Samples~/DI/README.md +13 -13
- package/Samples~/Mini Combat/README.md +15 -15
- package/Samples~/Mini Combat/Walkthrough.md +12 -12
- package/Samples~/UI Buttons + Inspector/README.md +4 -4
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoConstructorGenerator.cs +4 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxMessageIdGenerator.cs +4 -0
- package/Tests/Runtime/Core/DiagnosticsTests.cs +3 -3
- package/Tests/Runtime/Core/DxMessagingStaticStateTests.cs +69 -0
- package/Tests/Runtime/Core/DxMessagingStaticStateTests.cs.meta +11 -0
- package/package.json +1 -1
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj +0 -20
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj.meta +0 -7
package/AGENTS.md
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Project Structure & Module Organization
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
- Package manifest:
|
|
5
|
+
- [Runtime](Runtime/) — core library (`DxMessaging.Core`) and Unity components (`DxMessaging.Unity`).
|
|
6
|
+
- [Editor](Editor/) — editor utilities, analyzers, and setup (`DxMessaging.Editor`).
|
|
7
|
+
- [SourceGenerators](SourceGenerators/) — Roslyn source generators (`netstandard2.0`).
|
|
8
|
+
- [Tests/Runtime](Tests/Runtime/) — NUnit/Unity Test Framework tests (e.g., [Core Nominal tests](Tests/Runtime/Core/NominalTests.cs)).
|
|
9
|
+
- [Docs](Docs/) — usage patterns and examples.
|
|
10
|
+
- Package manifest: [package.json](package.json) (published to NPM/UPM).
|
|
11
11
|
|
|
12
12
|
## Build, Test, and Development Commands
|
|
13
13
|
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
|
|
18
18
|
## Coding Style & Naming Conventions
|
|
19
19
|
|
|
20
|
-
- Indent with 4 spaces for `.cs` (JSON/YAML: 2). CRLF, UTF‑8 BOM (see
|
|
20
|
+
- Indent with 4 spaces for `.cs` (JSON/YAML: 2). CRLF, UTF‑8 BOM (see [.editorconfig](.editorconfig)).
|
|
21
21
|
- Prefer explicit types over `var`. Braces required. `using` directives inside the namespace.
|
|
22
|
-
- Naming: `PascalCase` for types/methods/properties; interfaces `I*`; type parameters `T*`; events prefixed `On*`; public fields lowerCamelCase (matches examples in
|
|
22
|
+
- Naming: `PascalCase` for types/methods/properties; interfaces `I*`; type parameters `T*`; events prefixed `On*`; public fields lowerCamelCase (matches examples in the [README](README.md)).
|
|
23
23
|
- Place code under `DxMessaging.Core`, `DxMessaging.Unity`, or `DxMessaging.Editor` as appropriate.
|
|
24
24
|
- Do not use underscores in function names, especially test function names.
|
|
25
25
|
- Do not use regions, anywhere, ever.
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
## Testing Guidelines
|
|
30
30
|
|
|
31
31
|
- Frameworks: NUnit + Unity Test Framework. Use `[Test]`/`[UnityTest]` as needed.
|
|
32
|
-
- Location: add files under
|
|
32
|
+
- Location: add files under [Tests/Runtime](Tests/Runtime/) `<Area>/` named `*Tests.cs` with classes `*Tests`.
|
|
33
33
|
- Keep tests independent: prefer a local `MessageBus` and explicit `MessageRegistrationToken` lifecycles.
|
|
34
34
|
- Do not use underscores in test function names.
|
|
35
35
|
- Prefer expressive assertions and failure messages so it is clear what exactly is failing when a test fails.
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
## Commit & Pull Request Guidelines
|
|
44
44
|
|
|
45
45
|
- Commits: short, imperative subject; group related changes; reference issues/PRs (e.g., “Fix registration dedupe (#123)”).
|
|
46
|
-
- PRs: include a clear description, linked issues, before/after notes for performance changes (see
|
|
47
|
-
- Releasing: changes to
|
|
46
|
+
- PRs: include a clear description, linked issues, before/after notes for performance changes (see [Tests/Runtime/Benchmarks](Tests/Runtime/Benchmarks/)), and tests for bug fixes/features.
|
|
47
|
+
- Releasing: changes to [package.json](package.json) on `master` may trigger the NPM publish workflow.
|
|
48
48
|
|
|
49
49
|
## Security & Configuration Tips
|
|
50
50
|
|
|
51
|
-
- Editor analyzer DLLs are copied into the Unity project by
|
|
51
|
+
- Editor analyzer DLLs are copied into the Unity project by [SetupCscRsp.cs](Editor/SetupCscRsp.cs); do not commit generated DLLs into this repo.
|
|
52
52
|
- Keep public APIs minimal and consistent; avoid breaking changes without a major version bump.
|
package/Docs/Comparisons.md
CHANGED
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
|
|
29
29
|
## Performance Benchmarks
|
|
30
30
|
|
|
31
|
-
These sections are auto-updated by the PlayMode comparison benchmarks in
|
|
31
|
+
These sections are auto-updated by the PlayMode comparison benchmarks in the [Comparison Performance PlayMode tests](../Tests/Runtime/Benchmarks/ComparisonPerformanceTests.cs). Run the suite locally to refresh the tables.
|
|
32
32
|
|
|
33
33
|
### Comparisons (Windows)
|
|
34
34
|
|
|
35
35
|
| Message Tech | Operations / Second | Allocations? |
|
|
36
36
|
| ---------------------------------- | ------------------- | ------------ |
|
|
37
|
-
| DxMessaging (Untargeted) - No-Copy | 14,
|
|
38
|
-
| UniRx MessageBroker | 18,
|
|
39
|
-
| MessagePipe (Global) | 97,
|
|
40
|
-
| Zenject SignalBus | 2,
|
|
37
|
+
| DxMessaging (Untargeted) - No-Copy | 14,640,000 | No |
|
|
38
|
+
| UniRx MessageBroker | 18,074,000 | No |
|
|
39
|
+
| MessagePipe (Global) | 97,824,000 | No |
|
|
40
|
+
| Zenject SignalBus | 2,354,000 | Yes |
|
|
41
41
|
|
|
42
42
|
### Comparisons (macOS)
|
|
43
43
|
|
|
@@ -36,7 +36,7 @@ new GameEvent().Emit(); // Both DoWork() and ProcessLater() execute
|
|
|
36
36
|
- Ensures all listeners see a consistent view of the registration state
|
|
37
37
|
- Makes debugging and reasoning about message flow easier
|
|
38
38
|
|
|
39
|
-
This snapshot behavior is extensively tested in
|
|
39
|
+
This snapshot behavior is extensively tested in the [Mutation During Emission tests](../Tests/Runtime/Core/MutationDuringEmissionTests.cs).
|
|
40
40
|
|
|
41
41
|
---
|
|
42
42
|
|
package/Docs/Performance.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Performance Benchmarks
|
|
2
2
|
|
|
3
|
-
This page is auto-updated by the Unity PlayMode benchmark tests in
|
|
3
|
+
This page is auto-updated by the Unity PlayMode benchmark tests in the [Performance PlayMode benchmark suite](../Tests/Runtime/Benchmarks/PerformanceTests.cs).
|
|
4
4
|
|
|
5
5
|
How it works:
|
|
6
6
|
|
|
@@ -8,23 +8,23 @@ How it works:
|
|
|
8
8
|
- The benchmark test writes an OS-specific section below with a markdown table.
|
|
9
9
|
- CI runs skip writing to avoid noisy diffs.
|
|
10
10
|
|
|
11
|
-
See also:
|
|
11
|
+
See also: [Performance optimizations](./DesignAndArchitecture.md#performance-optimizations) for design details.
|
|
12
12
|
|
|
13
13
|
## Windows
|
|
14
14
|
|
|
15
15
|
| Message Tech | Operations / Second | Allocations? |
|
|
16
16
|
| ------------------------------------------ | ------------------- | ------------ |
|
|
17
|
-
| Unity | 2,
|
|
18
|
-
| DxMessaging (GameObject) - Normal | 8,
|
|
19
|
-
| DxMessaging (Component) - Normal | 8,
|
|
20
|
-
| DxMessaging (GameObject) - No-Copy | 9,
|
|
21
|
-
| DxMessaging (Component) - No-Copy | 9,
|
|
22
|
-
| DxMessaging (Untargeted) - No-Copy | 14,
|
|
23
|
-
| DxMessaging (Untargeted) - Interceptors | 6,
|
|
24
|
-
| DxMessaging (Untargeted) - Post-Processors | 5,
|
|
25
|
-
| Reflexive (One Argument) | 2,
|
|
26
|
-
| Reflexive (Two Arguments) | 2,
|
|
27
|
-
| Reflexive (Three Arguments) | 2,
|
|
17
|
+
| Unity | 2,504,000 | Yes |
|
|
18
|
+
| DxMessaging (GameObject) - Normal | 8,522,000 | No |
|
|
19
|
+
| DxMessaging (Component) - Normal | 8,524,000 | No |
|
|
20
|
+
| DxMessaging (GameObject) - No-Copy | 9,398,000 | No |
|
|
21
|
+
| DxMessaging (Component) - No-Copy | 9,508,000 | No |
|
|
22
|
+
| DxMessaging (Untargeted) - No-Copy | 14,742,000 | No |
|
|
23
|
+
| DxMessaging (Untargeted) - Interceptors | 6,620,000 | No |
|
|
24
|
+
| DxMessaging (Untargeted) - Post-Processors | 5,234,000 | No |
|
|
25
|
+
| Reflexive (One Argument) | 2,840,000 | No |
|
|
26
|
+
| Reflexive (Two Arguments) | 2,352,000 | No |
|
|
27
|
+
| Reflexive (Three Arguments) | 2,318,000 | No |
|
|
28
28
|
|
|
29
29
|
## macOS
|
|
30
30
|
|
package/Docs/QuickReference.md
CHANGED
|
@@ -106,7 +106,7 @@ public sealed class DamageSystem : IStartable, IDisposable
|
|
|
106
106
|
}
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
-
Tip: Define `ZENJECT_PRESENT`, `VCONTAINER_PRESENT`, or `REFLEX_PRESENT` to enable the optional shims under
|
|
109
|
+
Tip: Define `ZENJECT_PRESENT`, `VCONTAINER_PRESENT`, or `REFLEX_PRESENT` to enable the optional shims under [Runtime/Unity/Integrations](../Runtime/Unity/Integrations/) that bind the builder automatically for those containers.
|
|
110
110
|
|
|
111
111
|
Interceptors and post‑processors
|
|
112
112
|
|
package/Docs/Reference.md
CHANGED
|
@@ -64,11 +64,11 @@ Unity bridge types
|
|
|
64
64
|
|
|
65
65
|
Source files (for exploration)
|
|
66
66
|
|
|
67
|
-
- Message bus interface: Runtime/Core/MessageBus/IMessageBus.cs
|
|
68
|
-
- Message bus: Runtime/Core/MessageBus/MessageBus.cs
|
|
69
|
-
- Message handler/token: Runtime/Core/MessageHandler.cs, Runtime/Core/MessageRegistrationToken.cs
|
|
70
|
-
- Emit helpers: Runtime/Core/Extensions/MessageExtensions.cs
|
|
71
|
-
- Attributes: Runtime/Core/Attributes
|
|
67
|
+
- Message bus interface: [IMessageBus](../Runtime/Core/MessageBus/IMessageBus.cs)
|
|
68
|
+
- Message bus: [MessageBus](../Runtime/Core/MessageBus/MessageBus.cs)
|
|
69
|
+
- Message handler/token: [MessageHandler](../Runtime/Core/MessageHandler.cs), [MessageRegistrationToken](../Runtime/Core/MessageRegistrationToken.cs)
|
|
70
|
+
- Emit helpers: [MessageExtensions](../Runtime/Core/Extensions/MessageExtensions.cs)
|
|
71
|
+
- Attributes: [Attributes directory](../Runtime/Core/Attributes/)
|
|
72
72
|
|
|
73
73
|
API tables (quick view)
|
|
74
74
|
|
|
Binary file
|
|
@@ -37,6 +37,9 @@ namespace DxMessaging.Editor.CustomEditors
|
|
|
37
37
|
_listenerFoldouts.Clear();
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/// <summary>
|
|
41
|
+
/// Draws the custom inspector, including diagnostics summaries and listener management controls.
|
|
42
|
+
/// </summary>
|
|
40
43
|
public override void OnInspectorGUI()
|
|
41
44
|
{
|
|
42
45
|
base.OnInspectorGUI();
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
namespace DxMessaging.Editor
|
|
2
2
|
{
|
|
3
3
|
#if UNITY_EDITOR
|
|
4
|
+
using Core;
|
|
4
5
|
using Core.MessageBus;
|
|
5
6
|
using Settings;
|
|
6
7
|
using UnityEditor;
|
|
8
|
+
using UnityEngine;
|
|
7
9
|
|
|
8
10
|
/// <summary>
|
|
9
11
|
/// Applies DxMessaging Editor settings to global runtime defaults on domain load.
|
|
@@ -11,12 +13,67 @@ namespace DxMessaging.Editor
|
|
|
11
13
|
[InitializeOnLoad]
|
|
12
14
|
public static class DxMessagingEditorInitializer
|
|
13
15
|
{
|
|
16
|
+
private static bool s_playModeWarningIssued;
|
|
17
|
+
|
|
14
18
|
static DxMessagingEditorInitializer()
|
|
15
19
|
{
|
|
20
|
+
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
|
|
21
|
+
ApplyEditorSettings();
|
|
22
|
+
WarnIfDomainReloadDisabled();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private static void OnPlayModeStateChanged(PlayModeStateChange stateChange)
|
|
26
|
+
{
|
|
27
|
+
if (
|
|
28
|
+
stateChange == PlayModeStateChange.EnteredEditMode
|
|
29
|
+
|| stateChange == PlayModeStateChange.EnteredPlayMode
|
|
30
|
+
)
|
|
31
|
+
{
|
|
32
|
+
ApplyEditorSettings();
|
|
33
|
+
WarnIfDomainReloadDisabled();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
|
38
|
+
private static void ApplySettingsBeforeSceneLoad()
|
|
39
|
+
{
|
|
40
|
+
if (!Application.isPlaying)
|
|
41
|
+
{
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
ApplyEditorSettings();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private static void ApplyEditorSettings()
|
|
49
|
+
{
|
|
50
|
+
DxMessagingStaticState.Reset();
|
|
16
51
|
DxMessagingSettings settings = DxMessagingSettings.GetOrCreateSettings();
|
|
17
|
-
IMessageBus.
|
|
52
|
+
IMessageBus.GlobalDiagnosticsTargets = settings.DiagnosticsTargets;
|
|
18
53
|
IMessageBus.GlobalMessageBufferSize = settings.MessageBufferSize;
|
|
19
54
|
}
|
|
55
|
+
|
|
56
|
+
private static void WarnIfDomainReloadDisabled()
|
|
57
|
+
{
|
|
58
|
+
DxMessagingSettings settings = DxMessagingSettings.GetOrCreateSettings();
|
|
59
|
+
if (
|
|
60
|
+
s_playModeWarningIssued
|
|
61
|
+
|| settings.SuppressDomainReloadWarning
|
|
62
|
+
|| !EditorSettings.enterPlayModeOptionsEnabled
|
|
63
|
+
|| (EditorSettings.enterPlayModeOptions & EnterPlayModeOptions.DisableDomainReload)
|
|
64
|
+
== 0
|
|
65
|
+
)
|
|
66
|
+
{
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
s_playModeWarningIssued = true;
|
|
71
|
+
Debug.LogWarning(
|
|
72
|
+
"[DxMessaging] Enter Play Mode Options are disabling domain reload. "
|
|
73
|
+
+ "DxMessaging resets its internal statics, but third-party static state will persist. "
|
|
74
|
+
+ "Audit integration code or re-enable domain reload if inconsistent behaviour occurs."
|
|
75
|
+
);
|
|
76
|
+
}
|
|
20
77
|
}
|
|
21
78
|
#endif
|
|
22
79
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
namespace DxMessaging.Editor
|
|
2
|
+
{
|
|
3
|
+
#if UNITY_EDITOR
|
|
4
|
+
using Core;
|
|
5
|
+
using Core.MessageBus;
|
|
6
|
+
using UnityEditor;
|
|
7
|
+
using UnityEngine;
|
|
8
|
+
|
|
9
|
+
internal static class DxMessagingMenu
|
|
10
|
+
{
|
|
11
|
+
private const string Root = "Tools/Wallstop Studios/DxMessaging/";
|
|
12
|
+
|
|
13
|
+
[MenuItem(Root + "Reset Static State")]
|
|
14
|
+
private static void ResetStatics()
|
|
15
|
+
{
|
|
16
|
+
DxMessagingStaticState.Reset();
|
|
17
|
+
Debug.Log("[DxMessaging] Static state reset.");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
[MenuItem(Root + "Toggle Global Diagnostics")]
|
|
21
|
+
private static void ToggleGlobalDiagnostics()
|
|
22
|
+
{
|
|
23
|
+
DiagnosticsTarget current = IMessageBus.GlobalDiagnosticsTargets;
|
|
24
|
+
DiagnosticsTarget next = current switch
|
|
25
|
+
{
|
|
26
|
+
DiagnosticsTarget.Off => DiagnosticsTarget.Editor,
|
|
27
|
+
DiagnosticsTarget.Editor => DiagnosticsTarget.Runtime,
|
|
28
|
+
DiagnosticsTarget.Runtime => DiagnosticsTarget.All,
|
|
29
|
+
DiagnosticsTarget.All => DiagnosticsTarget.Off,
|
|
30
|
+
_ => DiagnosticsTarget.Off,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
IMessageBus.GlobalDiagnosticsTargets = next;
|
|
34
|
+
Debug.Log($"[DxMessaging] Global diagnostics targets set to {next}.");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
#endif
|
|
38
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
namespace DxMessaging.Editor
|
|
2
|
+
{
|
|
3
|
+
#if UNITY_EDITOR && UNITY_2021_3_OR_NEWER
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
using DxMessaging.Unity;
|
|
6
|
+
using UnityEditor.Build;
|
|
7
|
+
using UnityEditor.Build.Reporting;
|
|
8
|
+
using UnityEngine;
|
|
9
|
+
using UnityEngine.SceneManagement;
|
|
10
|
+
|
|
11
|
+
/// <summary>
|
|
12
|
+
/// Ensures MessagingComponent instances do not carry runtime registrations into player builds.
|
|
13
|
+
/// </summary>
|
|
14
|
+
internal sealed class DxMessagingSceneBuildProcessor : IProcessSceneWithReport
|
|
15
|
+
{
|
|
16
|
+
public int callbackOrder => int.MaxValue;
|
|
17
|
+
|
|
18
|
+
/// <summary>
|
|
19
|
+
/// Strips runtime-only messaging state from the scene before it is serialized into the build.
|
|
20
|
+
/// </summary>
|
|
21
|
+
/// <param name="scene">Scene currently being processed.</param>
|
|
22
|
+
/// <param name="report">Build report associated with the scene export.</param>
|
|
23
|
+
public void OnProcessScene(Scene scene, BuildReport report)
|
|
24
|
+
{
|
|
25
|
+
if (!scene.IsValid() || !scene.isLoaded)
|
|
26
|
+
{
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
MessagingComponent[] components = FindMessagingComponents(scene);
|
|
31
|
+
if (components == null || components.Length == 0)
|
|
32
|
+
{
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
int cleared = 0;
|
|
37
|
+
for (int i = 0; i < components.Length; ++i)
|
|
38
|
+
{
|
|
39
|
+
MessagingComponent component = components[i];
|
|
40
|
+
if (component != null && component.EditorResetRuntimeState())
|
|
41
|
+
{
|
|
42
|
+
cleared++;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (cleared > 0 && report != null)
|
|
47
|
+
{
|
|
48
|
+
Debug.Log(
|
|
49
|
+
$"[DxMessaging] Cleared {cleared} MessagingComponent instance(s) in scene '{scene.path}' prior to build."
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private static MessagingComponent[] FindMessagingComponents(Scene scene)
|
|
55
|
+
{
|
|
56
|
+
List<MessagingComponent> buffer = new List<MessagingComponent>();
|
|
57
|
+
GameObject[] roots = scene.GetRootGameObjects();
|
|
58
|
+
for (int i = 0; i < roots.Length; ++i)
|
|
59
|
+
{
|
|
60
|
+
GameObject root = roots[i];
|
|
61
|
+
if (root == null)
|
|
62
|
+
{
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
MessagingComponent[] components = root.GetComponentsInChildren<MessagingComponent>(
|
|
67
|
+
includeInactive: true
|
|
68
|
+
);
|
|
69
|
+
if (components == null || components.Length == 0)
|
|
70
|
+
{
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
buffer.AddRange(components);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return buffer.ToArray();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
#endif
|
|
81
|
+
}
|
|
@@ -2,8 +2,10 @@ namespace DxMessaging.Editor.Settings
|
|
|
2
2
|
{
|
|
3
3
|
#if UNITY_EDITOR
|
|
4
4
|
using System.Linq;
|
|
5
|
+
using Core.MessageBus;
|
|
5
6
|
using UnityEditor;
|
|
6
7
|
using UnityEngine;
|
|
8
|
+
using UnityEngine.Serialization;
|
|
7
9
|
|
|
8
10
|
/// <summary>
|
|
9
11
|
/// Project-wide DxMessaging settings asset (Editor-only).
|
|
@@ -18,18 +20,26 @@ namespace DxMessaging.Editor.Settings
|
|
|
18
20
|
private const string SettingsPath = "Assets/Editor/DxMessagingSettings.asset";
|
|
19
21
|
|
|
20
22
|
[SerializeField]
|
|
21
|
-
internal
|
|
23
|
+
internal DiagnosticsTarget _diagnosticsTargets = DiagnosticsTarget.Off;
|
|
24
|
+
|
|
25
|
+
[SerializeField]
|
|
26
|
+
[HideInInspector]
|
|
27
|
+
[FormerlySerializedAs("_enableDiagnosticsInEditor")]
|
|
28
|
+
private bool _legacyEnableDiagnosticsInEditor;
|
|
22
29
|
|
|
23
30
|
[SerializeField]
|
|
24
31
|
internal int _messageBufferSize = DefaultBufferSize;
|
|
25
32
|
|
|
33
|
+
[SerializeField]
|
|
34
|
+
internal bool _suppressDomainReloadWarning = true;
|
|
35
|
+
|
|
26
36
|
/// <summary>
|
|
27
|
-
///
|
|
37
|
+
/// Controls <see cref="DiagnosticsTarget"/> values applied to <see cref="IMessageBus.GlobalDiagnosticsTargets"/>.
|
|
28
38
|
/// </summary>
|
|
29
|
-
public
|
|
39
|
+
public DiagnosticsTarget DiagnosticsTargets
|
|
30
40
|
{
|
|
31
|
-
get =>
|
|
32
|
-
set =>
|
|
41
|
+
get => _diagnosticsTargets;
|
|
42
|
+
set => _diagnosticsTargets = value;
|
|
33
43
|
}
|
|
34
44
|
|
|
35
45
|
/// <summary>
|
|
@@ -41,6 +51,15 @@ namespace DxMessaging.Editor.Settings
|
|
|
41
51
|
set => _messageBufferSize = value;
|
|
42
52
|
}
|
|
43
53
|
|
|
54
|
+
/// <summary>
|
|
55
|
+
/// When true, suppresses the Enter Play Mode Options domain reload warning in the Editor.
|
|
56
|
+
/// </summary>
|
|
57
|
+
public bool SuppressDomainReloadWarning
|
|
58
|
+
{
|
|
59
|
+
get => _suppressDomainReloadWarning;
|
|
60
|
+
set => _suppressDomainReloadWarning = value;
|
|
61
|
+
}
|
|
62
|
+
|
|
44
63
|
/// <summary>
|
|
45
64
|
/// Loads the settings asset if present, otherwise creates it with sensible defaults.
|
|
46
65
|
/// </summary>
|
|
@@ -62,8 +81,9 @@ namespace DxMessaging.Editor.Settings
|
|
|
62
81
|
if (settings == null)
|
|
63
82
|
{
|
|
64
83
|
settings = CreateInstance<DxMessagingSettings>();
|
|
65
|
-
settings.
|
|
84
|
+
settings._diagnosticsTargets = DiagnosticsTarget.Off;
|
|
66
85
|
settings._messageBufferSize = DefaultBufferSize;
|
|
86
|
+
settings._suppressDomainReloadWarning = true;
|
|
67
87
|
if (!AssetDatabase.IsValidFolder("Assets/Editor"))
|
|
68
88
|
{
|
|
69
89
|
AssetDatabase.CreateFolder("Assets", "Editor");
|
|
@@ -72,6 +92,17 @@ namespace DxMessaging.Editor.Settings
|
|
|
72
92
|
AssetDatabase.SaveAssets();
|
|
73
93
|
}
|
|
74
94
|
|
|
95
|
+
if (
|
|
96
|
+
settings._diagnosticsTargets == DiagnosticsTarget.Off
|
|
97
|
+
&& settings._legacyEnableDiagnosticsInEditor
|
|
98
|
+
)
|
|
99
|
+
{
|
|
100
|
+
settings._diagnosticsTargets = DiagnosticsTarget.Editor;
|
|
101
|
+
settings._legacyEnableDiagnosticsInEditor = false;
|
|
102
|
+
EditorUtility.SetDirty(settings);
|
|
103
|
+
AssetDatabase.SaveAssets();
|
|
104
|
+
}
|
|
105
|
+
|
|
75
106
|
return settings;
|
|
76
107
|
}
|
|
77
108
|
|
|
@@ -2,6 +2,7 @@ namespace DxMessaging.Editor.Settings
|
|
|
2
2
|
{
|
|
3
3
|
#if UNITY_EDITOR
|
|
4
4
|
using System.Collections.Generic;
|
|
5
|
+
using Core.MessageBus;
|
|
5
6
|
using UnityEditor;
|
|
6
7
|
using UnityEngine;
|
|
7
8
|
|
|
@@ -21,6 +22,11 @@ namespace DxMessaging.Editor.Settings
|
|
|
21
22
|
)
|
|
22
23
|
: base(path, scope) { }
|
|
23
24
|
|
|
25
|
+
/// <summary>
|
|
26
|
+
/// Initializes the serialized settings backing store when the settings page is opened.
|
|
27
|
+
/// </summary>
|
|
28
|
+
/// <param name="searchContext">Search text provided by the Project Settings window.</param>
|
|
29
|
+
/// <param name="rootElement">Root visual element for UI Toolkit-based providers.</param>
|
|
24
30
|
public override void OnActivate(
|
|
25
31
|
string searchContext,
|
|
26
32
|
UnityEngine.UIElements.VisualElement rootElement
|
|
@@ -29,28 +35,60 @@ namespace DxMessaging.Editor.Settings
|
|
|
29
35
|
_messagingSettings = DxMessagingSettings.GetSerializedSettings();
|
|
30
36
|
}
|
|
31
37
|
|
|
38
|
+
/// <summary>
|
|
39
|
+
/// Renders the DxMessaging settings UI and persists any modifications.
|
|
40
|
+
/// </summary>
|
|
41
|
+
/// <param name="searchContext">Search text provided by the Project Settings window.</param>
|
|
32
42
|
public override void OnGUI(string searchContext)
|
|
33
43
|
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
nameof(DxMessagingSettings._enableDiagnosticsInEditor)
|
|
37
|
-
),
|
|
38
|
-
new GUIContent("Global Diagnostics Mode")
|
|
44
|
+
SerializedProperty targetsProp = _messagingSettings.FindProperty(
|
|
45
|
+
nameof(DxMessagingSettings._diagnosticsTargets)
|
|
39
46
|
);
|
|
47
|
+
DiagnosticsTarget currentTargets = (DiagnosticsTarget)targetsProp.enumValueFlag;
|
|
48
|
+
DiagnosticsTarget updatedTargets = (DiagnosticsTarget)
|
|
49
|
+
EditorGUILayout.EnumFlagsField(
|
|
50
|
+
new GUIContent(
|
|
51
|
+
"Diagnostics Targets",
|
|
52
|
+
"Select where global diagnostics should be enabled by default. Combine flags for multiple targets."
|
|
53
|
+
),
|
|
54
|
+
currentTargets
|
|
55
|
+
);
|
|
56
|
+
if (updatedTargets != currentTargets)
|
|
57
|
+
{
|
|
58
|
+
targetsProp.enumValueFlag = (int)updatedTargets;
|
|
59
|
+
}
|
|
40
60
|
EditorGUILayout.PropertyField(
|
|
41
61
|
_messagingSettings.FindProperty(nameof(DxMessagingSettings._messageBufferSize)),
|
|
42
|
-
new GUIContent(
|
|
62
|
+
new GUIContent(
|
|
63
|
+
"Message Buffer Size",
|
|
64
|
+
"Number of emissions kept per bus/token when diagnostics mode is active."
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
EditorGUILayout.PropertyField(
|
|
68
|
+
_messagingSettings.FindProperty(
|
|
69
|
+
nameof(DxMessagingSettings._suppressDomainReloadWarning)
|
|
70
|
+
),
|
|
71
|
+
new GUIContent(
|
|
72
|
+
"Suppress Domain Reload Warning",
|
|
73
|
+
"Disable the warning shown when Enter Play Mode Options skips domain reload; DxMessaging still resets its statics."
|
|
74
|
+
)
|
|
43
75
|
);
|
|
44
76
|
|
|
45
77
|
_messagingSettings.ApplyModifiedProperties();
|
|
46
78
|
}
|
|
47
79
|
|
|
48
80
|
[SettingsProvider]
|
|
81
|
+
/// <summary>
|
|
82
|
+
/// Factory used by Unity to register the DxMessaging project settings page.
|
|
83
|
+
/// </summary>
|
|
84
|
+
/// <returns>Configured settings provider instance.</returns>
|
|
49
85
|
public static SettingsProvider CreateDxMessagingSettingsProvider()
|
|
50
86
|
{
|
|
51
87
|
DxMessagingSettingsProvider provider = new("Project/DxMessaging")
|
|
52
88
|
{
|
|
53
|
-
keywords = new HashSet<string>(
|
|
89
|
+
keywords = new HashSet<string>(
|
|
90
|
+
new[] { "DxMessaging", "Diagnostics", "MessageBus", "Targets" }
|
|
91
|
+
),
|
|
54
92
|
};
|
|
55
93
|
|
|
56
94
|
return provider;
|
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ Need install instructions for Git URLs, scoped registries, or tarballs? Jump to
|
|
|
52
52
|
|
|
53
53
|
1. **Untargeted** - "Everyone listen!" (pause game, settings changed)
|
|
54
54
|
1. **Targeted** - "Tell Player to heal" (commands to specific entities)
|
|
55
|
-
1. **Broadcast** - "
|
|
55
|
+
1. **Broadcast** - "I took damage" (things that happen to _you_ that others can observe)
|
|
56
56
|
|
|
57
57
|
**One line:** It's the event system Unity should have shipped with - type-safe, leak-proof, and actually debuggable. 🚀
|
|
58
58
|
|