Skip to content

Commit 65c25a1

Browse files
Apply suggestions from code review
Co-authored-by: Emma <emma.mcmillan@unity3d.com>
1 parent b3bf6b3 commit 65c25a1

2 files changed

Lines changed: 17 additions & 61 deletions

File tree

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

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,14 @@ public void Initialize(bool warnInvalid = true)
142142
{
143143
m_Prefabs.Add(networkPrefab);
144144
#if UNIFIED_NETCODE && UNIFIED_NGO_REGISTERS_PREFABS
145-
if (!PrefabTable.ContainsKey(networkPrefab.SourcePrefabGlobalObjectIdHash))
146-
{
147-
PrefabTable.Add(networkPrefab.SourcePrefabGlobalObjectIdHash, networkPrefab);
148-
}
145+
PrefabTable.TryAdd(networkPrefab.SourcePrefabGlobalObjectIdHash, networkPrefab);
149146
#endif
150147
}
151148
else
152149
{
153150
removeList?.Add(networkPrefab);
154151
#if UNIFIED_NETCODE && UNIFIED_NGO_REGISTERS_PREFABS
155-
if (PrefabTable.ContainsKey(networkPrefab.SourcePrefabGlobalObjectIdHash))
156-
{
157-
PrefabTable.Remove(networkPrefab.SourcePrefabGlobalObjectIdHash);
158-
}
152+
PrefabTable.Remove(networkPrefab.SourcePrefabGlobalObjectIdHash);
159153
#endif
160154
}
161155
}
@@ -166,20 +160,14 @@ public void Initialize(bool warnInvalid = true)
166160
{
167161
m_Prefabs.Add(networkPrefab);
168162
#if UNIFIED_NETCODE && UNIFIED_NGO_REGISTERS_PREFABS
169-
if (!PrefabTable.ContainsKey(networkPrefab.SourcePrefabGlobalObjectIdHash))
170-
{
171-
PrefabTable.Add(networkPrefab.SourcePrefabGlobalObjectIdHash, networkPrefab);
172-
}
163+
PrefabTable.TryAdd(networkPrefab.SourcePrefabGlobalObjectIdHash, networkPrefab);
173164
#endif
174165
}
175166
else
176167
{
177168
removeList?.Add(networkPrefab);
178169
#if UNIFIED_NETCODE && UNIFIED_NGO_REGISTERS_PREFABS
179-
if (PrefabTable.ContainsKey(networkPrefab.SourcePrefabGlobalObjectIdHash))
180-
{
181-
PrefabTable.Remove(networkPrefab.SourcePrefabGlobalObjectIdHash);
182-
}
170+
PrefabTable.Remove(networkPrefab.SourcePrefabGlobalObjectIdHash);
183171
#endif
184172
}
185173
}
@@ -214,10 +202,7 @@ public bool Add(NetworkPrefab networkPrefab)
214202
m_Prefabs.Add(networkPrefab);
215203
m_RuntimeAddedPrefabs.Add(networkPrefab);
216204
#if UNIFIED_NETCODE && UNIFIED_NGO_REGISTERS_PREFABS
217-
if (!PrefabTable.ContainsKey(networkPrefab.SourcePrefabGlobalObjectIdHash))
218-
{
219-
PrefabTable.Add(networkPrefab.SourcePrefabGlobalObjectIdHash, networkPrefab);
220-
}
205+
PrefabTable.TryAdd(networkPrefab.SourcePrefabGlobalObjectIdHash, networkPrefab);
221206
#endif
222207
return true;
223208
}
@@ -247,10 +232,7 @@ public void Remove(NetworkPrefab prefab)
247232
OverrideToNetworkPrefab.Remove(prefab.TargetPrefabGlobalObjectIdHash);
248233
NetworkPrefabOverrideLinks.Remove(prefab.SourcePrefabGlobalObjectIdHash);
249234
#if UNIFIED_NETCODE && UNIFIED_NGO_REGISTERS_PREFABS
250-
if (PrefabTable.ContainsKey(prefab.SourcePrefabGlobalObjectIdHash))
251-
{
252-
PrefabTable.Remove(prefab.SourcePrefabGlobalObjectIdHash);
253-
}
235+
PrefabTable.Remove(prefab.SourcePrefabGlobalObjectIdHash);
254236
#endif
255237
}
256238

@@ -401,7 +383,7 @@ private bool AddPrefabRegistration(NetworkPrefab networkPrefab)
401383

402384
#if UNIFIED_NGO_REGISTERS_PREFABS
403385
HasPendingGhostPrefabs = true;
404-
m_PendingGhostRegistration.Add(networkPrefab);
386+
m_PendingGhostRegistration.TryAdd(networkPrefab);
405387
#endif
406388
}
407389
#endif

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

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ internal void InitializeNetcodeWorld()
13751375
{
13761376
if (NetCode.Netcode.IsActive)
13771377
{
1378-
NetworkLog.LogInfo($"[{nameof(InitializeNetcodeWorld)}] Netcode is not active but has an instance at this point.");
1378+
Log.Info(new Context(LogLevel.Normal, "Netcode is not active but has an instance at this point."));
13791379
}
13801380
/// !! Important !!
13811381
/// Clear out any pre-existing configuration in the event this applicatioin instance has already been connected to a session.
@@ -1396,12 +1396,12 @@ private bool UnifiedIsConfiguredCorrectly()
13961396
{
13971397
if (NetCodeConfig.Global == null)
13981398
{
1399-
Debug.LogError($"[{nameof(NetworkManager)}][Unified] You must create a {nameof(NetCodeConfig)} and set it to a single world in order to run in hybrid mode!");
1399+
Log.Error(new Context(LogLevel.Error, "You must create a {nameof(NetCodeConfig)} and set it to a single world in order to run in hybrid mode!").AddTag("Unified"));
14001400
return false;
14011401
}
14021402
if (NetCodeConfig.Global.HostWorldModeSelection != NetCodeConfig.HostWorldMode.SingleWorld)
14031403
{
1404-
Debug.LogError($"[{nameof(NetworkManager)}][Unified] You must configure {nameof(NetCodeConfig)} to only use a single world in order to run in hybrid mode!");
1404+
Log.Error(new Context(LogLevel.Error, "You must configure {nameof(NetCodeConfig)} to only use a single world in order to run in hybrid mode!").AddTag("Unified"));
14051405
return false;
14061406
}
14071407
return true;
@@ -1451,18 +1451,12 @@ public bool StartServer()
14511451
}
14521452
if (LogLevel <= LogLevel.Developer)
14531453
{
1454-
Debug.Log("Creating world: Default world");
1454+
Log.Info(new Context(LogLevel.Developer, "Creating world: Default world"));
14551455
}
14561456
InitializeNetcodeWorld();
1457-
return InternalStartServer();
14581457
}
1459-
else
1460-
{
1461-
return InternalStartServer();
1462-
}
1463-
#else
1464-
return InternalStartServer();
14651458
#endif
1459+
return InternalStartServer();
14661460
}
14671461

14681462
internal bool InternalStartServer()
@@ -1534,21 +1528,11 @@ public bool StartClient()
15341528
ShutdownInternal();
15351529
return false;
15361530
}
1537-
if (LogLevel <= LogLevel.Developer)
1538-
{
1539-
Debug.Log("Creating world: Default world");
1540-
}
1531+
Log.Info(new Context(LogLevel.Developer, "Creating world: Default world"));
15411532
InitializeNetcodeWorld();
1542-
return InternalStartClient();
1543-
}
1544-
else
1545-
{
1546-
return InternalStartClient();
15471533
}
1548-
#else
1549-
return InternalStartClient();
15501534
#endif
1551-
1535+
return InternalStartClient();
15521536
}
15531537

15541538
internal bool InternalStartClient()
@@ -1618,21 +1602,11 @@ public bool StartHost()
16181602
ShutdownInternal();
16191603
return false;
16201604
}
1621-
if (LogLevel <= LogLevel.Developer)
1622-
{
1623-
Debug.Log("Creating world: Default world");
1624-
}
1605+
Log.Info(new Context(LogLevel.Developer, "Creating world: Default world"));
16251606
InitializeNetcodeWorld();
1626-
return InternalStartHost();
16271607
}
1628-
else
1629-
{
1630-
return InternalStartHost();
1631-
}
1632-
#else
1633-
return InternalStartHost();
16341608
#endif
1635-
1609+
return InternalStartHost();
16361610
}
16371611

16381612
internal bool InternalStartHost()
@@ -1859,7 +1833,7 @@ internal void ShutdownInternal()
18591833
}
18601834
catch (Exception ex)
18611835
{
1862-
Debug.LogException(ex);
1836+
Log.Exception(ex);
18631837
}
18641838
}
18651839
#endif

0 commit comments

Comments
 (0)