Skip to content

Commit df11388

Browse files
committed
Address review comments
1 parent d8c72f4 commit df11388

7 files changed

Lines changed: 28 additions & 63 deletions

File tree

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@ public class CommandLineOptions
1616
public static CommandLineOptions Instance { get; private set; }
1717

1818
// Contains the current application instance domain's command line arguments
19-
private static List<string> s_CommandLineArguments = new List<string>(Environment.GetCommandLineArgs());
19+
private static readonly List<string> k_CommandLineArguments = new List<string>(Environment.GetCommandLineArgs());
2020

2121
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
2222
private static void InitializeOnLoad()
2323
{
2424
Instance = new CommandLineOptions();
25-
#if UNITY_EDITOR
26-
s_CommandLineArguments = new List<string>(Environment.GetCommandLineArgs());
27-
#endif
2825
}
2926

3027
/// <summary>
@@ -34,10 +31,10 @@ private static void InitializeOnLoad()
3431
/// <returns><see cref="string"/>Value of the command line argument passed in.</returns>
3532
public string GetArg(string arg)
3633
{
37-
var argIndex = s_CommandLineArguments.IndexOf(arg);
38-
if (argIndex >= 0 && argIndex < s_CommandLineArguments.Count - 1)
34+
var argIndex = k_CommandLineArguments.IndexOf(arg);
35+
if (argIndex >= 0 && argIndex < k_CommandLineArguments.Count - 1)
3936
{
40-
return s_CommandLineArguments[argIndex + 1];
37+
return k_CommandLineArguments[argIndex + 1];
4138
}
4239
return null;
4340
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,13 +1725,10 @@ internal void SetIsDestroying()
17251725
IsDestroying = true;
17261726
}
17271727

1728-
private void OnDisable()
1728+
private void OnDestroy()
17291729
{
17301730
SceneManager.activeSceneChanged -= CurrentlyActiveSceneChanged;
1731-
}
17321731

1733-
private void OnDestroy()
1734-
{
17351732
// Apply the is destroying flag
17361733
SetIsDestroying();
17371734

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ namespace Unity.Netcode
1010
/// Log configuration containing :
1111
/// - <see cref="LogNetworkManagerRole"/> used in LogContextNetworkManager.cs
1212
/// - <see cref="LogSerializationOrder"/> used in SceneEventData.cs
13-
/// - <see cref="EnableSerializationLogs"/> used in SceneEventData.cs
1413
/// </summary>
1514
internal struct LogConfiguration
1615
{
1716
internal bool LogNetworkManagerRole;
1817
internal bool LogSerializationOrder;
19-
internal bool EnableSerializationLogs;
2018
}
2119

2220
/// <summary>

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

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

47
namespace Unity.Netcode
58
{
@@ -142,15 +145,15 @@ internal static Dictionary<Type, NetworkMessageTypes> GetMessageTypesMap()
142145
}
143146

144147
#if UNITY_EDITOR
145-
[UnityEditor.InitializeOnLoadMethod]
148+
[InitializeOnLoadMethod]
146149
public static void NotifyOnPlayStateChange()
147150
{
148-
UnityEditor.EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
151+
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
149152
}
150153

151-
public static void OnPlayModeStateChanged(UnityEditor.PlayModeStateChange change)
154+
public static void OnPlayModeStateChanged(PlayModeStateChange change)
152155
{
153-
if (change == UnityEditor.PlayModeStateChange.ExitingPlayMode)
156+
if (change == PlayModeStateChange.ExitingPlayMode)
154157
{
155158
// Clear out the network message types, because ILPP-generated RuntimeInitializeOnLoad code will
156159
// run again and add more messages to it.

com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventData.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ private int SortNetworkObjects(NetworkObject first, NetworkObject second)
443443
return 0;
444444
}
445445

446+
internal bool EnableSerializationLogs = false;
447+
446448
private void LogArray(byte[] data, int start = 0, int stop = 0, StringBuilder builder = null)
447449
{
448450
var usingExternalBuilder = builder != null;
@@ -524,7 +526,7 @@ internal void Serialize(FastBufferWriter writer)
524526

525527
WriteSceneSynchronizationData(writer);
526528

527-
if (NetworkLog.Config.EnableSerializationLogs)
529+
if (EnableSerializationLogs)
528530
{
529531
LogArray(writer.ToArray(), 0, writer.Length);
530532
}
@@ -574,7 +576,7 @@ private unsafe void CopyInternalBuffer(ref FastBufferWriter writer)
574576
internal void WriteSceneSynchronizationData(FastBufferWriter writer)
575577
{
576578
var builder = (StringBuilder)null;
577-
if (NetworkLog.Config.EnableSerializationLogs)
579+
if (EnableSerializationLogs)
578580
{
579581
builder = new StringBuilder();
580582
builder.AppendLine($"[Write][Synchronize-Start][WPos: {writer.Position}] Begin:");
@@ -589,7 +591,7 @@ internal void WriteSceneSynchronizationData(FastBufferWriter writer)
589591
{
590592
writer.WriteValueSafe(m_InternalBufferSize);
591593
CopyInternalBuffer(ref writer);
592-
if (NetworkLog.Config.EnableSerializationLogs)
594+
if (EnableSerializationLogs)
593595
{
594596
LogArray(writer.ToArray(), positionStart);
595597
}
@@ -604,7 +606,7 @@ internal void WriteSceneSynchronizationData(FastBufferWriter writer)
604606

605607
// Write the number of NetworkObjects we are serializing
606608
writer.WriteValueSafe(m_NetworkObjectsSync.Count);
607-
if (NetworkLog.Config.EnableSerializationLogs)
609+
if (EnableSerializationLogs)
608610
{
609611
builder.AppendLine($"[Synchronize Objects][positionStart: {positionStart}][WPos: {writer.Position}][NO-Count: {m_NetworkObjectsSync.Count}] Begin:");
610612
}
@@ -621,15 +623,15 @@ internal void WriteSceneSynchronizationData(FastBufferWriter writer)
621623
serializedObject.Serialize(writer);
622624
var noStop = writer.Position;
623625
totalBytes += noStop - noStart;
624-
if (NetworkLog.Config.EnableSerializationLogs)
626+
if (EnableSerializationLogs)
625627
{
626628
var offStart = noStart - (positionStart + sizeof(int));
627629
var offStop = noStop - (positionStart + sizeof(int));
628630
builder.AppendLine($"[Head: {offStart}][Tail: {offStop}][Size: {offStop - offStart}][{networkObject.name}][NID-{networkObject.NetworkObjectId}][Children: {networkObject.ChildNetworkBehaviours.Count}]");
629631
LogArray(writer.ToArray(), noStart, noStop, builder);
630632
}
631633
}
632-
if (NetworkLog.Config.EnableSerializationLogs)
634+
if (EnableSerializationLogs)
633635
{
634636
UnityEngine.Debug.Log(builder.ToString());
635637
}
@@ -653,7 +655,7 @@ internal void WriteSceneSynchronizationData(FastBufferWriter writer)
653655
// Write the total size written to the stream by NetworkObjects being serialized
654656
writer.WriteValueSafe(bytesWritten);
655657
writer.Seek(positionEnd);
656-
if (NetworkLog.Config.EnableSerializationLogs)
658+
if (EnableSerializationLogs)
657659
{
658660
LogArray(writer.ToArray(), positionStart);
659661
}
@@ -773,7 +775,7 @@ internal void Deserialize(FastBufferReader reader)
773775
case SceneEventType.Synchronize:
774776
{
775777
reader.ReadValueSafe(out ActiveSceneHash);
776-
if (NetworkLog.Config.EnableSerializationLogs)
778+
if (EnableSerializationLogs)
777779
{
778780
LogArray(reader.ToArray(), 0, reader.Length);
779781
}
@@ -843,7 +845,7 @@ internal void CopySceneSynchronizationData(FastBufferReader reader)
843845
m_HasInternalBuffer = true;
844846
// We use Allocator.Persistent since scene synchronization will most likely take longer than 4 frames
845847
InternalBuffer = new FastBufferReader(reader.GetUnsafePtrAtCurrentPosition(), Allocator.Persistent, sizeToCopy);
846-
if (NetworkLog.Config.EnableSerializationLogs)
848+
if (EnableSerializationLogs)
847849
{
848850
LogArray(InternalBuffer.ToArray());
849851
}
@@ -1085,7 +1087,7 @@ private void DeserializeDespawnedInScenePlacedNetworkObjects()
10851087
internal void SynchronizeSceneNetworkObjects(NetworkManager networkManager)
10861088
{
10871089
var builder = (StringBuilder)null;
1088-
if (NetworkLog.Config.EnableSerializationLogs)
1090+
if (EnableSerializationLogs)
10891091
{
10901092
builder = new StringBuilder();
10911093
}
@@ -1094,7 +1096,7 @@ internal void SynchronizeSceneNetworkObjects(NetworkManager networkManager)
10941096
{
10951097
// Process all spawned NetworkObjects for this network session
10961098
InternalBuffer.ReadValueSafe(out int newObjectsCount);
1097-
if (NetworkLog.Config.EnableSerializationLogs)
1099+
if (EnableSerializationLogs)
10981100
{
10991101
builder.AppendLine($"[Read][Synchronize Objects][WPos: {InternalBuffer.Position}][NO-Count: {newObjectsCount}] Begin:");
11001102
}
@@ -1113,7 +1115,7 @@ internal void SynchronizeSceneNetworkObjects(NetworkManager networkManager)
11131115
var spawnedNetworkObject = NetworkObject.Deserialize(serializedObject, InternalBuffer, networkManager);
11141116

11151117
var noStop = InternalBuffer.Position;
1116-
if (NetworkLog.Config.EnableSerializationLogs)
1118+
if (EnableSerializationLogs)
11171119
{
11181120
builder.AppendLine($"[Head: {noStart}][Tail: {noStop}][Size: {noStop - noStart}][{spawnedNetworkObject.name}][NID-{spawnedNetworkObject.NetworkObjectId}][Children: {spawnedNetworkObject.ChildNetworkBehaviours.Count}]");
11191121
LogArray(InternalBuffer.ToArray(), noStart, noStop, builder);
@@ -1127,7 +1129,7 @@ internal void SynchronizeSceneNetworkObjects(NetworkManager networkManager)
11271129
}
11281130
}
11291131
}
1130-
if (NetworkLog.Config.EnableSerializationLogs)
1132+
if (EnableSerializationLogs)
11311133
{
11321134
UnityEngine.Debug.Log(builder.ToString());
11331135
}
@@ -1148,7 +1150,7 @@ internal void SynchronizeSceneNetworkObjects(NetworkManager networkManager)
11481150
catch (Exception ex)
11491151
{
11501152
UnityEngine.Debug.LogException(ex);
1151-
if (NetworkLog.Config.EnableSerializationLogs)
1153+
if (EnableSerializationLogs)
11521154
{
11531155
UnityEngine.Debug.Log(builder.ToString());
11541156
}

com.unity.netcode.gameobjects/Tests/Editor/FastEnterPlayModeTests.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

com.unity.netcode.gameobjects/Tests/Editor/FastEnterPlayModeTests.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)