Skip to content

Commit 46e09ab

Browse files
committed
Finalize addressing review comments
1 parent 9febb5e commit 46e09ab

17 files changed

Lines changed: 75 additions & 136 deletions

com.unity.netcode.gameobjects/Runtime/Components/RigidbodyContactEventManager.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ public interface IContactEventHandlerWithInfo : IContactEventHandler
7676
public class RigidbodyContactEventManager : MonoBehaviour
7777
{
7878
public static RigidbodyContactEventManager Instance { get; private set; }
79-
#if UNITY_EDITOR
80-
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
81-
private static void ResetStaticsOnLoad() => Instance = null;
82-
#endif
8379

8480
private struct JobResultStruct
8581
{
@@ -113,7 +109,7 @@ private void OnEnable()
113109
{
114110
m_ResultsArray = new NativeArray<JobResultStruct>(16, Allocator.Persistent);
115111
Physics.ContactEvent += Physics_ContactEvent;
116-
if (Instance != null)
112+
if (Instance != null || Instance != this)
117113
{
118114
NetworkLog.LogError($"[Invalid][Multiple Instances] Found more than one instance of {nameof(RigidbodyContactEventManager)}: {name} and {Instance.name}");
119115
NetworkLog.LogError($"[Disable][Additional Instance] Disabling {name} instance!");

com.unity.netcode.gameobjects/Runtime/Configuration/CommandLineOptions.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,16 @@ public class CommandLineOptions
1313
/// <summary>
1414
/// Command-line options singleton
1515
/// </summary>
16-
public static CommandLineOptions Instance
17-
{
18-
get
19-
{
20-
if (s_Instance == null)
21-
{
22-
s_Instance = new CommandLineOptions();
23-
}
24-
return s_Instance;
25-
}
26-
private set
27-
{
28-
s_Instance = value;
29-
}
30-
}
31-
private static CommandLineOptions s_Instance;
16+
public static CommandLineOptions Instance { get; private set; }
3217

3318
// Contains the current application instance domain's command line arguments
3419
private static List<string> s_CommandLineArguments = new List<string>(Environment.GetCommandLineArgs());
20+
3521
#if UNITY_EDITOR
3622
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
3723
private static void ResetStaticsOnLoad()
3824
{
3925
Instance = new CommandLineOptions();
40-
s_Instance = new CommandLineOptions();
41-
// Get all the command line arguments to be parsed later and/or modified
42-
// prior to being parsed (for testing purposes).
4326
s_CommandLineArguments = new List<string>(Environment.GetCommandLineArgs());
4427
}
4528
#endif

com.unity.netcode.gameobjects/Runtime/Core/ComponentFactory.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
#if UNITY_EDITOR
4-
using UnityEngine;
5-
#endif
63

74
namespace Unity.Netcode
85
{
@@ -18,7 +15,7 @@ internal static class ComponentFactory
1815

1916
private static Dictionary<Type, CreateObjectDelegate> s_Delegates = new Dictionary<Type, CreateObjectDelegate>();
2017
#if UNITY_EDITOR
21-
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
18+
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
2219
private static void ResetStaticsOnLoad() => s_Delegates = new Dictionary<Type, CreateObjectDelegate>();
2320
#endif
2421

com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ namespace Unity.Netcode
2121
[HelpURL(HelpUrls.NetworkManager)]
2222
public class NetworkManager : MonoBehaviour, INetworkUpdateSystem
2323
{
24+
#if UNITY_EDITOR
25+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
26+
private static void ResetStaticsOnLoad()
27+
{
28+
Singleton = null;
29+
OnInstantiated = null;
30+
OnDestroying = null;
31+
OnSingletonReady = null;
32+
OnNetworkManagerReset = null;
33+
IsDistributedAuthority = false;
34+
s_SerializedType = new List<Type>();
35+
DisableNotOptimizedSerializedType = false;
36+
}
37+
#endif
2438
/// <summary>
2539
/// Subscribe to this static event to get notifications when a <see cref="NetworkManager"/> instance has been instantiated.
2640
/// </summary>
@@ -31,7 +45,6 @@ public class NetworkManager : MonoBehaviour, INetworkUpdateSystem
3145
/// </summary>
3246
public static event Action<NetworkManager> OnDestroying;
3347

34-
3548
#if UNITY_EDITOR
3649
// Inspector view expand/collapse settings for this derived child class
3750
[HideInInspector]
@@ -1796,20 +1809,11 @@ internal abstract class NetcodeAnalytics
17961809
internal delegate void ResetNetworkManagerDelegate(NetworkManager manager);
17971810

17981811
internal static ResetNetworkManagerDelegate OnNetworkManagerReset;
1799-
//We already are in an #if UNITY_ENGINE def
1800-
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
1801-
private static void ResetStaticsOnLoad()
1802-
{
1803-
Singleton = null;
1804-
OnInstantiated = null;
1805-
OnDestroying = null;
1806-
OnSingletonReady = null;
1807-
OnNetworkManagerReset = null;
1808-
IsDistributedAuthority = false;
1809-
s_SerializedType = new List<Type>();
1810-
DisableNotOptimizedSerializedType = false;
1811-
}
18121812

1813+
1814+
/// <summary>
1815+
/// This is called by the Unity Editor reset button. See "OnNetworkManagerReset" from "NetworkManagerHelper.cs" file.
1816+
/// </summary>
18131817
private void Reset()
18141818
{
18151819
OnNetworkManagerReset?.Invoke(this);

com.unity.netcode.gameobjects/Runtime/Core/NetworkUpdateLoop.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ public static PlayerLoopSystem CreateLoopSystem()
292292
private static void Initialize()
293293
{
294294
#if UNITY_EDITOR
295+
// Reset statics
295296
s_UpdateSystemSets = new Dictionary<NetworkUpdateStage, HashSet<INetworkUpdateSystem>>();
296297
s_UpdateSystemArrays = new Dictionary<NetworkUpdateStage, INetworkUpdateSystem[]>();
297298
foreach (NetworkUpdateStage updateStage in Enum.GetValues(typeof(NetworkUpdateStage)))

com.unity.netcode.gameobjects/Runtime/Logging/NetworkLog.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@
66

77
namespace Unity.Netcode
88
{
9+
/// <summary>
10+
/// Log configuration containing :
11+
/// - <see cref="LogNetworkManagerRole"/> used in LogContextNetworkManager.cs
12+
/// - <see cref="LogSerializationOrder"/> used in SceneEventData.cs
13+
/// - <see cref="EnableSerializationLogs"/> used in SceneEventData.cs
14+
/// </summary>
915
internal struct LogConfiguration
1016
{
1117
internal bool LogNetworkManagerRole;
18+
internal bool LogSerializationOrder;
19+
internal bool EnableSerializationLogs;
1220
}
1321

1422
/// <summary>
15-
/// Helper class for logging
23+
/// Helper class for logging.
1624
/// </summary>
1725
public static class NetworkLog
1826
{
@@ -58,7 +66,7 @@ internal static void ConfigureIntegrationTestLogging(NetworkManager networkManag
5866
internal static void LogWarning(Context context) => s_Log.Warning(context);
5967

6068
/// <summary>
61-
/// Locally logs a error log with Netcode prefixing.
69+
/// Locally logs an error log with Netcode prefixing.
6270
/// </summary>
6371
/// <param name="message">The message to log</param>
6472
[HideInCallstack]

com.unity.netcode.gameobjects/Runtime/Messaging/DeferredMessageManager.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System.Collections.Generic;
22
using Unity.Collections;
3-
#if UNITY_EDITOR
4-
using UnityEngine;
5-
#endif
63

74
namespace Unity.Netcode
85
{
@@ -100,7 +97,7 @@ public virtual unsafe void CleanupStaleTriggers()
10097
/// </summary>
10198
internal static bool IncludeMessageType = true;
10299
#if UNITY_EDITOR
103-
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
100+
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
104101
private static void ResetStaticsOnLoad() => IncludeMessageType = true;
105102
#endif
106103

com.unity.netcode.gameobjects/Runtime/Messaging/ILPPMessageProvider.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
#if UNITY_EDITOR
4-
using UnityEngine;
5-
using UnityEditor;
6-
#endif
73

84
namespace Unity.Netcode
95
{
@@ -55,7 +51,7 @@ internal struct ILPPMessageProvider : INetworkMessageProvider
5551
// Enable this for integration tests that need no message types defined
5652
internal static bool IntegrationTestNoMessages;
5753
#if UNITY_EDITOR
58-
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
54+
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
5955
private static void ResetStaticsOnLoad() => IntegrationTestNoMessages = false;
6056
#endif
6157

@@ -146,15 +142,15 @@ internal static Dictionary<Type, NetworkMessageTypes> GetMessageTypesMap()
146142
}
147143

148144
#if UNITY_EDITOR
149-
[InitializeOnLoadMethod]
145+
[UnityEditor.InitializeOnLoadMethod]
150146
public static void NotifyOnPlayStateChange()
151147
{
152-
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
148+
UnityEditor.EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
153149
}
154150

155-
public static void OnPlayModeStateChanged(PlayModeStateChange change)
151+
public static void OnPlayModeStateChanged(UnityEditor.PlayModeStateChange change)
156152
{
157-
if (change == PlayModeStateChange.ExitingPlayMode)
153+
if (change == UnityEditor.PlayModeStateChange.ExitingPlayMode)
158154
{
159155
// Clear out the network message types, because ILPP-generated RuntimeInitializeOnLoad code will
160156
// run again and add more messages to it.

com.unity.netcode.gameobjects/Runtime/Messaging/INetworkMessage.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
#if UNITY_6000_6_OR_NEWER
2-
using Unity.Scripting.LifecycleManagement;
3-
#endif
4-
51
namespace Unity.Netcode
62
{
73
/// <summary>
@@ -49,7 +45,7 @@ internal interface INetworkMessage
4945
}
5046

5147
#if UNITY_6000_6_OR_NEWER
52-
[AutoStaticsCleanup]
48+
[Scripting.LifecycleManagement.AutoStaticsCleanup]
5349
#endif
5450
internal static partial class MessageDeliveryType<T> where T : INetworkMessage
5551
{

com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#if MULTIPLAYER_TOOLS
22
using System;
33
using System.Collections.Generic;
4-
#if UNITY_EDITOR
5-
using UnityEngine;
6-
#endif
74
using Unity.Multiplayer.Tools;
85
using Unity.Multiplayer.Tools.MetricTypes;
96
using Unity.Multiplayer.Tools.NetStats;
@@ -14,20 +11,8 @@ namespace Unity.Netcode
1411
internal class NetworkMetrics : INetworkMetrics
1512
{
1613
private const ulong k_MaxMetricsPerFrame = 1000L;
17-
private static Dictionary<uint, string> s_SceneEventTypeNames;
14+
private readonly static Dictionary<uint, string> s_SceneEventTypeNames;
1815
private static ProfilerMarker s_FrameDispatch = new ProfilerMarker($"{nameof(NetworkMetrics)}.DispatchFrame");
19-
#if UNITY_EDITOR
20-
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
21-
private static void ResetStaticsOnLoad()
22-
{
23-
s_SceneEventTypeNames = new Dictionary<uint, string>();
24-
foreach (SceneEventType type in Enum.GetValues(typeof(SceneEventType)))
25-
{
26-
s_SceneEventTypeNames[(uint)type] = type.ToString();
27-
}
28-
s_FrameDispatch = new ProfilerMarker($"{nameof(NetworkMetrics)}.DispatchFrame");
29-
}
30-
#endif
3116

3217
static NetworkMetrics()
3318
{
@@ -40,12 +25,7 @@ static NetworkMetrics()
4025

4126
private static string GetSceneEventTypeName(uint typeCode)
4227
{
43-
if (!s_SceneEventTypeNames.TryGetValue(typeCode, out string name))
44-
{
45-
name = "Unknown";
46-
}
47-
48-
return name;
28+
return s_SceneEventTypeNames.GetValueOrDefault(typeCode, "Unknown");
4929
}
5030

5131
private readonly Counter m_TransportBytesSent = new Counter(NetworkMetricTypes.TotalBytesSent.Id)

0 commit comments

Comments
 (0)