mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkClient - Use TryGetComponent (#3331)
This eliminates allocations, at least in the editor, per Unity docs.
This commit is contained in:
parent
82a7e752a8
commit
993caf3b36
@ -571,8 +571,7 @@ public static void RegisterPrefab(GameObject prefab, uint newAssetId)
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
if (!prefab.TryGetComponent<NetworkIdentity>(out NetworkIdentity identity))
|
||||
{
|
||||
Debug.LogError($"Could not register '{prefab.name}' since it contains no NetworkIdentity component");
|
||||
return;
|
||||
@ -598,8 +597,7 @@ public static void RegisterPrefab(GameObject prefab)
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
if (!prefab.TryGetComponent<NetworkIdentity>(out NetworkIdentity identity))
|
||||
{
|
||||
Debug.LogError($"Could not register '{prefab.name}' since it contains no NetworkIdentity component");
|
||||
return;
|
||||
@ -635,8 +633,7 @@ public static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler,
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
if (!prefab.TryGetComponent<NetworkIdentity>(out NetworkIdentity identity))
|
||||
{
|
||||
Debug.LogError($"Could not register handler for '{prefab.name}' since it contains no NetworkIdentity component");
|
||||
return;
|
||||
@ -683,8 +680,7 @@ public static void RegisterPrefab(GameObject prefab, uint newAssetId, SpawnHandl
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
if (!prefab.TryGetComponent<NetworkIdentity>(out NetworkIdentity identity))
|
||||
{
|
||||
Debug.LogError($"Could not register handler for '{prefab.name}' since it contains no NetworkIdentity component");
|
||||
return;
|
||||
@ -750,8 +746,7 @@ public static void RegisterPrefab(GameObject prefab, SpawnHandlerDelegate spawnH
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
if (!prefab.TryGetComponent<NetworkIdentity>(out NetworkIdentity identity))
|
||||
{
|
||||
Debug.LogError($"Could not register handler for '{prefab.name}' since it contains no NetworkIdentity component");
|
||||
return;
|
||||
@ -815,8 +810,7 @@ public static void UnregisterPrefab(GameObject prefab)
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
if (!prefab.TryGetComponent<NetworkIdentity>(out NetworkIdentity identity))
|
||||
{
|
||||
Debug.LogError($"Could not unregister '{prefab.name}' since it contains no NetworkIdentity component");
|
||||
return;
|
||||
@ -1101,12 +1095,13 @@ static NetworkIdentity SpawnPrefab(SpawnMessage message)
|
||||
Debug.LogError($"Spawn Handler returned null, Handler assetId '{message.assetId}'");
|
||||
return null;
|
||||
}
|
||||
NetworkIdentity identity = obj.GetComponent<NetworkIdentity>();
|
||||
if (identity == null)
|
||||
|
||||
if (!obj.TryGetComponent<NetworkIdentity>(out NetworkIdentity identity))
|
||||
{
|
||||
Debug.LogError($"Object Spawned by handler did not have a NetworkIdentity, Handler assetId '{message.assetId}'");
|
||||
return null;
|
||||
}
|
||||
|
||||
return identity;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user