mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00: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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
if (!prefab.TryGetComponent<NetworkIdentity>(out NetworkIdentity identity))
|
||||||
if (identity == null)
|
|
||||||
{
|
{
|
||||||
Debug.LogError($"Could not register '{prefab.name}' since it contains no NetworkIdentity component");
|
Debug.LogError($"Could not register '{prefab.name}' since it contains no NetworkIdentity component");
|
||||||
return;
|
return;
|
||||||
@ -598,8 +597,7 @@ public static void RegisterPrefab(GameObject prefab)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
if (!prefab.TryGetComponent<NetworkIdentity>(out NetworkIdentity identity))
|
||||||
if (identity == null)
|
|
||||||
{
|
{
|
||||||
Debug.LogError($"Could not register '{prefab.name}' since it contains no NetworkIdentity component");
|
Debug.LogError($"Could not register '{prefab.name}' since it contains no NetworkIdentity component");
|
||||||
return;
|
return;
|
||||||
@ -635,8 +633,7 @@ public static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
if (!prefab.TryGetComponent<NetworkIdentity>(out NetworkIdentity identity))
|
||||||
if (identity == null)
|
|
||||||
{
|
{
|
||||||
Debug.LogError($"Could not register handler for '{prefab.name}' since it contains no NetworkIdentity component");
|
Debug.LogError($"Could not register handler for '{prefab.name}' since it contains no NetworkIdentity component");
|
||||||
return;
|
return;
|
||||||
@ -683,8 +680,7 @@ public static void RegisterPrefab(GameObject prefab, uint newAssetId, SpawnHandl
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
if (!prefab.TryGetComponent<NetworkIdentity>(out NetworkIdentity identity))
|
||||||
if (identity == null)
|
|
||||||
{
|
{
|
||||||
Debug.LogError($"Could not register handler for '{prefab.name}' since it contains no NetworkIdentity component");
|
Debug.LogError($"Could not register handler for '{prefab.name}' since it contains no NetworkIdentity component");
|
||||||
return;
|
return;
|
||||||
@ -750,8 +746,7 @@ public static void RegisterPrefab(GameObject prefab, SpawnHandlerDelegate spawnH
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
if (!prefab.TryGetComponent<NetworkIdentity>(out NetworkIdentity identity))
|
||||||
if (identity == null)
|
|
||||||
{
|
{
|
||||||
Debug.LogError($"Could not register handler for '{prefab.name}' since it contains no NetworkIdentity component");
|
Debug.LogError($"Could not register handler for '{prefab.name}' since it contains no NetworkIdentity component");
|
||||||
return;
|
return;
|
||||||
@ -815,8 +810,7 @@ public static void UnregisterPrefab(GameObject prefab)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
if (!prefab.TryGetComponent<NetworkIdentity>(out NetworkIdentity identity))
|
||||||
if (identity == null)
|
|
||||||
{
|
{
|
||||||
Debug.LogError($"Could not unregister '{prefab.name}' since it contains no NetworkIdentity component");
|
Debug.LogError($"Could not unregister '{prefab.name}' since it contains no NetworkIdentity component");
|
||||||
return;
|
return;
|
||||||
@ -1101,12 +1095,13 @@ static NetworkIdentity SpawnPrefab(SpawnMessage message)
|
|||||||
Debug.LogError($"Spawn Handler returned null, Handler assetId '{message.assetId}'");
|
Debug.LogError($"Spawn Handler returned null, Handler assetId '{message.assetId}'");
|
||||||
return null;
|
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}'");
|
Debug.LogError($"Object Spawned by handler did not have a NetworkIdentity, Handler assetId '{message.assetId}'");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return identity;
|
return identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user