From 7387b2a47a0d5195b01dacbab5f8559142ef7dfb Mon Sep 17 00:00:00 2001 From: vis2k Date: Sun, 16 Dec 2018 18:55:24 +0100 Subject: [PATCH] NetworkScene.SetLocalObject removed. Moved code into ClientScene.SetLocalObject and NetworkServer.SetLocalObject instead. --- Mirror/Runtime/ClientScene.cs | 20 ++++++++++++++++++-- Mirror/Runtime/NetworkScene.cs | 22 ---------------------- Mirror/Runtime/NetworkServer.cs | 16 +++++++++++++++- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/Mirror/Runtime/ClientScene.cs b/Mirror/Runtime/ClientScene.cs index e4c2a7ddb..cbbfa58b3 100644 --- a/Mirror/Runtime/ClientScene.cs +++ b/Mirror/Runtime/ClientScene.cs @@ -273,8 +273,24 @@ public static void DestroyAllClientObjects() public static void SetLocalObject(uint netId, NetworkIdentity ni) { - // if still receiving initial state, dont set isClient - s_NetworkScene.SetLocalObject(netId, ni, s_IsSpawnFinished, false); + if (LogFilter.Debug) { Debug.Log("ClientScene.SetLocalObject " + netId + " " + ni); } + + if (ni != null) + { + // if still receiving initial state, dont set isClient + if (s_IsSpawnFinished) ni.EnableIsClient(); + + // !Contains check needed to avoid dictionary 'out of sync' error + // because SetLocalObject is called from a foreach loop + if (!NetworkIdentity.spawned.ContainsKey(netId)) + { + NetworkIdentity.spawned[netId] = ni; + } + } + else + { + NetworkIdentity.spawned[netId] = null; + } } public static GameObject FindLocalObject(uint netId) diff --git a/Mirror/Runtime/NetworkScene.cs b/Mirror/Runtime/NetworkScene.cs index 8d99aec26..62892427f 100644 --- a/Mirror/Runtime/NetworkScene.cs +++ b/Mirror/Runtime/NetworkScene.cs @@ -18,28 +18,6 @@ internal void Shutdown() ClearSpawners(); } - internal void SetLocalObject(uint netId, NetworkIdentity ni, bool isClient, bool isServer) - { - if (LogFilter.Debug) { Debug.Log("SetLocalObject " + netId + " " + ni); } - - if (ni != null) - { - if (isClient) ni.EnableIsClient(); - if (isServer) ni.EnableIsServer(); - - // !Contains check needed to avoid dictionary 'out of sync' error - // because SetLocalObject is called from a foreach loop - if (!NetworkIdentity.spawned.ContainsKey(netId)) - { - NetworkIdentity.spawned[netId] = ni; - } - } - else - { - NetworkIdentity.spawned[netId] = null; - } - } - internal static void RegisterPrefab(GameObject prefab, Guid newAssetId) { NetworkIdentity view = prefab.GetComponent(); diff --git a/Mirror/Runtime/NetworkServer.cs b/Mirror/Runtime/NetworkServer.cs index fb4e4d597..2765c2a94 100644 --- a/Mirror/Runtime/NetworkServer.cs +++ b/Mirror/Runtime/NetworkServer.cs @@ -190,7 +190,21 @@ internal static void SetLocalObjectOnServer(uint netId, NetworkIdentity ni) { if (LogFilter.Debug) { Debug.Log("SetLocalObjectOnServer " + netId + " " + ni); } - s_NetworkScene.SetLocalObject(netId, ni, false, true); + if (ni != null) + { + ni.EnableIsServer(); + + // !Contains check needed to avoid dictionary 'out of sync' error + // because SetLocalObject is called from a foreach loop + if (!NetworkIdentity.spawned.ContainsKey(netId)) + { + NetworkIdentity.spawned[netId] = ni; + } + } + else + { + NetworkIdentity.spawned[netId] = null; + } } internal static void ActivateLocalClientScene()