From 425e3131dc78b37b686898df8b417a9609357988 Mon Sep 17 00:00:00 2001 From: vis2k Date: Sat, 6 Mar 2021 13:52:29 +0800 Subject: [PATCH] fix: NetworkServer.SpawnObserversForConnection refactored to support all visibility cases (ForceShown/ForceHidden/Default) and all systems (legacy/new/default). fixes #2606 --- Assets/Mirror/Runtime/NetworkServer.cs | 44 ++++++++++++++++++-------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/Assets/Mirror/Runtime/NetworkServer.cs b/Assets/Mirror/Runtime/NetworkServer.cs index bab79ce1e..e96a513b7 100644 --- a/Assets/Mirror/Runtime/NetworkServer.cs +++ b/Assets/Mirror/Runtime/NetworkServer.cs @@ -777,30 +777,48 @@ static void SpawnObserversForConnection(NetworkConnection conn) { // Debug.Log("Sending spawn message for current server objects name='" + identity.name + "' netId=" + identity.netId + " sceneId=" + identity.sceneId.ToString("X")); - // not force hidden? - if (identity.visible != Visibility.ForceHidden) + // we need to support three cases: + // - legacy system (identity has .visibility) + // - new system (networkserver has .aoi) + // - default case: no .visibility and no .aoi means add all + // connections by default) + // + // ForceHidden/ForceShown overwrite all systems so check it + // first! + + // ForceShown: add no matter what + if (identity.visible == Visibility.ForceShown) { - // legacy system support (for now) + identity.AddObserver(conn); + } + // ForceHidden: don't show no matter what + else if (identity.visible == Visibility.ForceHidden) + { + // do nothing + } + // default: legacy system / new system / no system support + else if (identity.visible == Visibility.Default) + { + // legacy system #pragma warning disable 618 if (identity.visibility != null) { + // call OnCheckObserver if (identity.visibility.OnCheckObserver(conn)) - { identity.AddObserver(conn); - } } #pragma warning restore 618 // new system + else if (aoi != null) + { + // call OnCheckObserver + if (aoi.OnCheckObserver(identity, conn)) + identity.AddObserver(conn); + } + // no system: add all observers by default else { - // add observer: - // -> if there is no interest management system then simply - // always add (everyone sees everyone by default) - // -> if there is a system then ask the system to check - if (aoi == null || aoi.OnCheckObserver(identity, conn)) - { - identity.AddObserver(conn); - } + identity.AddObserver(conn); } } }