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:
vis2k 2018-12-17 22:59:26 +01:00
parent 28a2246b32
commit 4088beed6c

View File

@ -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()