Fix: Client Broadcast Delta sent on Reliable channel instead of Unreliable

This commit is contained in:
ninjakickja 2024-01-19 00:53:45 +08:00
parent eb352f5485
commit 15ed88779c

View File

@ -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
}
}