mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
NetworkReader.ReadGameObject and ReadNetworkIdentity simplified: uses new spawned dict and avoids unnecessary '.gameObject' access. ReadNetworkIdentity also avoids unnecessary casting back from GameObject to NetworkIdentity.
This commit is contained in:
parent
28a2246b32
commit
4088beed6c
@ -223,21 +223,14 @@ public GameObject ReadGameObject()
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameObject go;
|
NetworkIdentity identity;
|
||||||
if (NetworkServer.active)
|
if (NetworkIdentity.spawned.TryGetValue(netId, out identity))
|
||||||
{
|
{
|
||||||
go = NetworkServer.FindLocalObject(netId);
|
return identity.gameObject;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
go = ClientScene.FindLocalObject(netId);
|
|
||||||
}
|
|
||||||
if (go == null)
|
|
||||||
{
|
|
||||||
if (LogFilter.Debug) { Debug.Log("ReadGameObject netId:" + netId + "go: null"); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return go;
|
if (LogFilter.Debug) { Debug.Log("ReadGameObject netId:" + netId + " not found in spawned"); }
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkIdentity ReadNetworkIdentity()
|
public NetworkIdentity ReadNetworkIdentity()
|
||||||
@ -247,22 +240,15 @@ public NetworkIdentity ReadNetworkIdentity()
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
GameObject go;
|
|
||||||
if (NetworkServer.active)
|
NetworkIdentity identity;
|
||||||
|
if (NetworkIdentity.spawned.TryGetValue(netId, out identity))
|
||||||
{
|
{
|
||||||
go = NetworkServer.FindLocalObject(netId);
|
return identity;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
go = ClientScene.FindLocalObject(netId);
|
|
||||||
}
|
|
||||||
if (go == null)
|
|
||||||
{
|
|
||||||
if (LogFilter.Debug) { Debug.Log("ReadNetworkIdentity netId:" + netId + "go: null"); }
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return go.GetComponent<NetworkIdentity>();
|
if (LogFilter.Debug) { Debug.Log("ReadNetworkIdentity netId:" + netId + " not found in spawned"); }
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
Loading…
Reference in New Issue
Block a user