diff --git a/Unity-Technologies-networking/Runtime/ClientScene.cs b/Unity-Technologies-networking/Runtime/ClientScene.cs index 678b14b91..db3f46f93 100644 --- a/Unity-Technologies-networking/Runtime/ClientScene.cs +++ b/Unity-Technologies-networking/Runtime/ClientScene.cs @@ -657,25 +657,24 @@ static void OnSyncEventMessage(NetworkMessage netMsg) static void OnSyncListMessage(NetworkMessage netMsg) { - var netId = netMsg.reader.ReadNetworkId(); - var cmdHash = (int)netMsg.reader.ReadPackedUInt32(); + SyncListMessage message = netMsg.ReadMessage(); - if (LogFilter.logDebug) { Debug.Log("ClientScene::OnSyncListMessage " + netId); } + if (LogFilter.logDebug) { Debug.Log("ClientScene::OnSyncListMessage " + message.netId); } NetworkIdentity uv; - if (s_NetworkScene.GetNetworkIdentity(netId, out uv)) + if (s_NetworkScene.GetNetworkIdentity(message.netId, out uv)) { - uv.HandleSyncList(cmdHash, netMsg.reader); + uv.HandleSyncList(message.syncListHash, new NetworkReader(message.payload)); } else { - if (LogFilter.logWarn) { Debug.LogWarning("Did not find target for SyncList message for " + netId); } + if (LogFilter.logWarn) { Debug.LogWarning("Did not find target for SyncList message for " + message.netId); } } #if UNITY_EDITOR UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, - (short)MsgType.SyncList, NetworkBehaviour.GetCmdHashHandlerName(cmdHash), 1); + (short)MsgType.SyncList, NetworkBehaviour.GetCmdHashHandlerName(message.syncListHash), 1); #endif } diff --git a/Unity-Technologies-networking/Runtime/Messages.cs b/Unity-Technologies-networking/Runtime/Messages.cs index 788916f08..b009283ef 100644 --- a/Unity-Technologies-networking/Runtime/Messages.cs +++ b/Unity-Technologies-networking/Runtime/Messages.cs @@ -203,6 +203,27 @@ public override void Serialize(NetworkWriter writer) } } + class SyncListMessage : MessageBase + { + public NetworkInstanceId netId; + public int syncListHash; + public byte[] payload; + + public override void Deserialize(NetworkReader reader) + { + netId = reader.ReadNetworkId(); + syncListHash = reader.ReadInt32(); // hash is always 4 full bytes, WritePackedInt would send 1 extra byte here + payload = reader.ReadBytesAndSize(); + } + + public override void Serialize(NetworkWriter writer) + { + writer.Write(netId); + writer.Write(syncListHash); + writer.WriteBytesAndSize(payload); + } + } + /* These are not used directly but manually serialized, these are here for reference. internal class SyncListMessage where T: struct { diff --git a/Unity-Technologies-networking/Runtime/SyncList.cs b/Unity-Technologies-networking/Runtime/SyncList.cs index 91a449624..6aa41e32b 100644 --- a/Unity-Technologies-networking/Runtime/SyncList.cs +++ b/Unity-Technologies-networking/Runtime/SyncList.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.ComponentModel; +using UnityEngine.Networking.NetworkSystem; namespace UnityEngine.Networking { @@ -249,16 +250,20 @@ void SendMsg(Operation op, int itemIndex, T item) return; } + + // construct and send message + SyncListMessage message = new SyncListMessage(); + message.netId = uv.netId; + message.syncListHash = m_CmdHash; + NetworkWriter writer = new NetworkWriter(); - writer.StartMessage((short)MsgType.SyncList); - writer.Write(uv.netId); - writer.WritePackedUInt32((uint)m_CmdHash); writer.Write((byte)op); writer.WritePackedUInt32((uint)itemIndex); SerializeItem(writer, item); - writer.FinishMessage(); - NetworkServer.SendBytesToReady(uv.gameObject, writer.ToArray(), m_Behaviour.GetNetworkChannel()); + message.payload = writer.ToArray(); + + NetworkServer.SendByChannelToReady(uv.gameObject, (short)MsgType.SyncList, message, m_Behaviour.GetNetworkChannel()); #if UNITY_EDITOR UnityEditor.NetworkDetailStats.IncrementStat(