From 4088beed6cd49fae9b43c0ec30fe393534349bcb Mon Sep 17 00:00:00 2001 From: vis2k Date: Mon, 17 Dec 2018 22:59:26 +0100 Subject: [PATCH] NetworkReader.ReadGameObject and ReadNetworkIdentity simplified: uses new spawned dict and avoids unnecessary '.gameObject' access. ReadNetworkIdentity also avoids unnecessary casting back from GameObject to NetworkIdentity. --- Mirror/Runtime/NetworkReader.cs | 36 ++++++++++----------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/Mirror/Runtime/NetworkReader.cs b/Mirror/Runtime/NetworkReader.cs index 97573fa7d..1c6ff7c4c 100644 --- a/Mirror/Runtime/NetworkReader.cs +++ b/Mirror/Runtime/NetworkReader.cs @@ -223,21 +223,14 @@ public GameObject ReadGameObject() return null; } - GameObject go; - if (NetworkServer.active) + NetworkIdentity identity; + if (NetworkIdentity.spawned.TryGetValue(netId, out identity)) { - go = NetworkServer.FindLocalObject(netId); - } - else - { - go = ClientScene.FindLocalObject(netId); - } - if (go == null) - { - if (LogFilter.Debug) { Debug.Log("ReadGameObject netId:" + netId + "go: null"); } + return identity.gameObject; } - return go; + if (LogFilter.Debug) { Debug.Log("ReadGameObject netId:" + netId + " not found in spawned"); } + return null; } public NetworkIdentity ReadNetworkIdentity() @@ -247,22 +240,15 @@ public NetworkIdentity ReadNetworkIdentity() { return null; } - GameObject go; - if (NetworkServer.active) + + NetworkIdentity identity; + if (NetworkIdentity.spawned.TryGetValue(netId, out identity)) { - go = NetworkServer.FindLocalObject(netId); - } - else - { - go = ClientScene.FindLocalObject(netId); - } - if (go == null) - { - if (LogFilter.Debug) { Debug.Log("ReadNetworkIdentity netId:" + netId + "go: null"); } - return null; + return identity; } - return go.GetComponent(); + if (LogFilter.Debug) { Debug.Log("ReadNetworkIdentity netId:" + netId + " not found in spawned"); } + return null; } public override string ToString()