From b640523f9bce9bfa19b7eec607cad841bc8e73f4 Mon Sep 17 00:00:00 2001 From: vis2k Date: Wed, 26 May 2021 18:27:50 +0800 Subject: [PATCH] NetworkClient.RegisterSystemHandlers: OnHostClientObjectDestroy/OnObjectDestroy merged to prepare for WorldState --- Assets/Mirror/Runtime/NetworkClient.cs | 34 +++++++++++++++----------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/Assets/Mirror/Runtime/NetworkClient.cs b/Assets/Mirror/Runtime/NetworkClient.cs index 39092c3c4..7a6f07054 100644 --- a/Assets/Mirror/Runtime/NetworkClient.cs +++ b/Assets/Mirror/Runtime/NetworkClient.cs @@ -103,7 +103,6 @@ internal static void RegisterSystemHandlers(bool hostMode) // 'message id not found' errors. if (hostMode) { - RegisterHandler(OnHostClientObjectDestroy); RegisterHandler(msg => {}, false); RegisterHandler(OnHostClientSpawn); // host mode doesn't need spawning @@ -115,13 +114,13 @@ internal static void RegisterSystemHandlers(bool hostMode) } else { - RegisterHandler(OnObjectDestroy); RegisterHandler(NetworkTime.OnClientPong, false); RegisterHandler(OnSpawn); RegisterHandler(OnObjectSpawnStarted); RegisterHandler(OnObjectSpawnFinished); RegisterHandler(OnEntityStateMessage); } + RegisterHandler(OnObjectDestroy); RegisterHandler(OnObjectHide); RegisterHandler(OnRPCMessage); } @@ -1109,17 +1108,6 @@ static void ClearNullFromSpawned() } // host mode callbacks ///////////////////////////////////////////////// - static void OnHostClientObjectDestroy(ObjectDestroyMessage message) - { - // Debug.Log("NetworkClient.OnLocalObjectObjDestroy netId:" + msg.netId); - - // TODO why do we do this? - // in host mode, .spawned is shared between server and client. - // removing it on client would remove it on server. - // huh. - NetworkIdentity.spawned.Remove(message.netId); - } - internal static void OnHostClientSpawn(SpawnMessage message) { if (NetworkIdentity.spawned.TryGetValue(message.netId, out NetworkIdentity localObject) && @@ -1178,7 +1166,25 @@ static void OnObjectHide(ObjectHideMessage message) } } - internal static void OnObjectDestroy(ObjectDestroyMessage message) => DestroyObject(message.netId); + internal static void OnObjectDestroy(ObjectDestroyMessage message) + { + // Debug.Log("NetworkClient.OnObjectDestroy netId:" + msg.netId); + + // host mode + if (isHostClient) + { + // TODO why do we do this? + // in host mode, .spawned is shared between server and client. + // removing it on client would remove it on server. + // huh. + NetworkIdentity.spawned.Remove(message.netId); + } + // client only + else + { + DestroyObject(message.netId); + } + } internal static void OnSpawn(SpawnMessage message) {