diff --git a/com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs b/com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs index 98a3aa1419..9961509cca 100644 --- a/com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs +++ b/com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs @@ -4,7 +4,6 @@ using Unity.Multiplayer.NetStats.Dispatch; using Unity.Multiplayer.NetStats.Metrics; using Unity.Multiplayer.NetStatsReporting; -using UnityEngine.Profiling; namespace Unity.Netcode { diff --git a/com.unity.netcode.gameobjects/Tests/Editor/Metrics.meta b/com.unity.netcode.gameobjects/Tests/Editor/Metrics.meta new file mode 100644 index 0000000000..bc962b1c81 --- /dev/null +++ b/com.unity.netcode.gameobjects/Tests/Editor/Metrics.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 87ddfad8823c4fe192fff56b7acc241b +timeCreated: 1629386688 \ No newline at end of file diff --git a/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs new file mode 100644 index 0000000000..1f243d32e1 --- /dev/null +++ b/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs @@ -0,0 +1,43 @@ +#if MULTIPLAYER_TOOLS + +using System; +using System.Linq; +using System.Reflection; +using NUnit.Framework; +using Unity.Multiplayer.MetricTypes; +using Unity.Multiplayer.NetStats.Dispatch; +using Unity.Multiplayer.NetStats.Metrics; + +namespace Unity.Netcode.EditorTests.Metrics +{ + public class NetworkMetricsRegistrationTests + { + static Type[] s_MetricTypes = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(x => x.GetTypes()) + .Where(x => x.GetInterfaces().Contains(typeof(INetworkMetricEvent))) + .ToArray(); + + [TestCaseSource(nameof(s_MetricTypes))] + public void ValidateThatAllMetricTypesAreRegistered(Type metricType) + { + var dispatcher = new NetworkMetrics().Dispatcher as MetricDispatcher; + Assert.NotNull(dispatcher); + + var collection = typeof(MetricDispatcher) + .GetField("m_Collection", BindingFlags.NonPublic | BindingFlags.Instance)? + .GetValue(dispatcher) as MetricCollection; + Assert.NotNull(collection); + + Assert.That( + collection.Metrics, + Has.Exactly(2).Matches( + eventMetric => + { + var eventType = eventMetric.GetType().GetGenericArguments()?.FirstOrDefault(); + return eventType == metricType; + })); + } + } +} + +#endif \ No newline at end of file diff --git a/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs.meta b/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs.meta new file mode 100644 index 0000000000..89ebdab722 --- /dev/null +++ b/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: af741f5e3d4f5544eaa68bb9bcaf54c6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Tests/Editor/com.unity.netcode.editortests.asmdef b/com.unity.netcode.gameobjects/Tests/Editor/com.unity.netcode.editortests.asmdef index 35dcb1ce8d..1c8e0294d9 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/com.unity.netcode.editortests.asmdef +++ b/com.unity.netcode.gameobjects/Tests/Editor/com.unity.netcode.editortests.asmdef @@ -3,12 +3,21 @@ "rootNamespace": "Unity.Netcode.EditorTests", "references": [ "Unity.Netcode.Runtime", - "Unity.Netcode.Editor" + "Unity.Netcode.Editor", + "Unity.Multiplayer.MetricTypes", + "Unity.Multiplayer.NetStats" ], "optionalUnityReferences": [ "TestAssemblies" ], "includePlatforms": [ "Editor" + ], + "versionDefines": [ + { + "name": "com.unity.multiplayer.tools", + "expression": "", + "define": "MULTIPLAYER_TOOLS" + } ] } \ No newline at end of file diff --git a/testproject-tools-integration/Packages/manifest.json b/testproject-tools-integration/Packages/manifest.json index 596ddb24dd..df82f39aee 100644 --- a/testproject-tools-integration/Packages/manifest.json +++ b/testproject-tools-integration/Packages/manifest.json @@ -3,7 +3,7 @@ "dependencies": { "com.unity.ide.rider": "3.0.7", "com.unity.netcode.gameobjects": "file:../../com.unity.netcode.gameobjects", - "com.unity.multiplayer.tools": "0.0.1-preview.2", + "com.unity.multiplayer.tools": "0.0.1-preview.3", "com.unity.multiplayer.transport.utp": "file:../../com.unity.multiplayer.transport.utp", "com.unity.test-framework": "1.1.26", "com.unity.modules.ai": "1.0.0",