From 15ed88779c51587b589e8d9b6289047231053171 Mon Sep 17 00:00:00 2001 From: ninjakickja <80569286+ninjakickja@users.noreply.github.com> Date: Fri, 19 Jan 2024 00:53:45 +0800 Subject: [PATCH] Fix: Client Broadcast Delta sent on Reliable channel instead of Unreliable --- .../HybridNetworkTransformV2.cs | 49 +++++++------------ 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/Assets/Mirror/Components/NetworkTransform/HybridNetworkTransformV2.cs b/Assets/Mirror/Components/NetworkTransform/HybridNetworkTransformV2.cs index 30006658a..fd65fe91f 100644 --- a/Assets/Mirror/Components/NetworkTransform/HybridNetworkTransformV2.cs +++ b/Assets/Mirror/Components/NetworkTransform/HybridNetworkTransformV2.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using UnityEngine; using System; +using UnityEditor.UIElements; +using UnityEditor; namespace Mirror { @@ -106,13 +108,11 @@ public class HybridNetworkTransformV2 : NetworkBehaviour #region Register Message Handlers public override void OnStartServer() { - base.OnStartServer(); if (!registeredHandlers) RegisterServerHandlers(); } public override void OnStartClient() { - base.OnStopClient(); if (!registeredHandlers) RegisterClientHandlers(); CmdRegisteredHandler(); @@ -363,7 +363,7 @@ protected virtual void ServerBroadcastFull() SyncDataFullMsg msg = new SyncDataFullMsg(netId, ComponentIndex, lastSentFullSyncData); SendToReadyObservers(netIdentity, msg, false, Channels.Reliable); // will exclude owner be problematic? - //RpcServerToClientSyncFull(lastSentFullSyncData); + //NetworkServer.SendToReadyObservers(netIdentity, msg, false, Channels.Reliable); // will exclude owner be problematic? } private byte NextFullSyncIndex() @@ -374,11 +374,6 @@ private byte NextFullSyncIndex() return lastSentFullSyncIndex; } - /*[ClientRpc] - void RpcServerToClientSyncFull(SyncDataFull syncData) => - OnServerToClientSyncFull(syncData); - */ - protected static void ServerToClientSyncFullHandler(SyncDataFullMsg msg) { if (!NetworkClient.spawned.ContainsKey(msg.netId)) return; @@ -427,7 +422,9 @@ protected virtual void ServerBroadcastDelta() SyncDataDeltaMsg msg = new SyncDataDeltaMsg(netId, ComponentIndex, syncDataDelta); SendToReadyObservers(netIdentity, msg, false, Channels.Unreliable); // will exclude owner be problematic? - //RpcServerToClientSyncDelta(syncDataDelta); + + //NetworkServer.SendToReadyObservers(netIdentity, msg, false, Channels.Unreliable); // will exclude owner be problematic? + } /*[ClientRpc (channel = Channels.Unreliable)] @@ -479,18 +476,8 @@ protected virtual void ClientBroadcastFull() SyncDataFullMsg msg = new SyncDataFullMsg(netId, ComponentIndex, lastSentFullSyncData); NetworkClient.Send(msg, Channels.Reliable); - //CmdClientToServerSyncFull(lastSentFullSyncData); } - /*[Command] - void CmdClientToServerSyncFull(SyncDataFull syncData) - { - OnClientToServerSyncFull(syncData); - - if (syncDirection == SyncDirection.ClientToServer) - RpcServerToClientSyncFull(syncData); - }*/ - protected static void ClientToServerSyncFullHandler(NetworkConnectionToClient conn, SyncDataFullMsg msg) { @@ -508,6 +495,7 @@ protected static void ClientToServerSyncFullHandler(NetworkConnectionToClient co if (networkIdentity.NetworkBehaviours[msg.componentId].syncDirection == SyncDirection.ClientToServer) nT.SendToReadyObservers(networkIdentity, msg, false, Channels.Reliable); // will exclude owner be problematic? + //NetworkServer.SendToReadyObservers(networkIdentity, msg, false, Channels.Reliable); // will exclude owner be problematic? } protected virtual void OnClientToServerSyncFull(SyncDataFull syncData) @@ -546,18 +534,8 @@ protected virtual void ClientBroadcastDelta() SyncDataDeltaMsg msg = new SyncDataDeltaMsg(netId, ComponentIndex, syncDataDelta); NetworkClient.Send(msg, Channels.Unreliable); - //CmdClientToServerSyncDelta(syncDataDelta); } - /*[Command(channel = Channels.Unreliable)] - void CmdClientToServerSyncDelta(SyncDataDelta delta) - { - OnClientToServerSyncDelta(delta); - - if (syncDirection == SyncDirection.ClientToServer) - RpcServerToClientSyncDelta(delta); - }*/ - protected static void ClientToServerSyncDeltaHandler(NetworkConnectionToClient conn, SyncDataDeltaMsg msg) { if (!NetworkServer.spawned.ContainsKey(msg.netId)) return; @@ -574,7 +552,8 @@ protected static void ClientToServerSyncDeltaHandler(NetworkConnectionToClient c nT.OnClientToServerSyncDelta(msg.syncData); if (networkIdentity.NetworkBehaviours[msg.componentId].syncDirection == SyncDirection.ClientToServer) - nT.SendToReadyObservers(networkIdentity, msg, false, Channels.Reliable); // will exclude owner be problematic? + nT.SendToReadyObservers(networkIdentity, msg, false, Channels.Unreliable); // will exclude owner be problematic? + //NetworkServer.SendToReadyObservers(networkIdentity, msg, false, Channels.Unreliable); // will exclude owner be problematic? } protected virtual void OnClientToServerSyncDelta(SyncDataDelta delta) @@ -837,6 +816,14 @@ protected virtual void CleanUpFullSyncDataPositionSync(ref SyncDataFull syncData if ((syncSettings & SyncSettings.SyncPosY) == 0) syncData.position.y = currentPosition.y; if ((syncSettings & SyncSettings.SyncPosZ) == 0) syncData.position.z = currentPosition.z; } - #endregion + #endregion + + +#if UNITY_EDITOR + void OnGUI() + { + syncSettings = (SyncSettings)EditorGUILayout.EnumFlagsField(syncSettings); + } +#endif } } \ No newline at end of file