static void OnSyncListMessage(NetworkMessage netMsg)
        {
            SyncListMessage message = netMsg.ReadMessage <SyncListMessage>();

            if (LogFilter.logDebug)
            {
                Debug.Log("ClientScene::OnSyncListMessage " + message.netId);
            }

            NetworkIdentity uv;

            if (s_NetworkScene.GetNetworkIdentity(message.netId, out uv))
            {
                uv.HandleSyncList(message.syncListHash, new NetworkReader(message.payload));
            }
            else
            {
                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(message.syncListHash), 1);
#endif
        }
예제 #2
0
        void SendMsg(Operation op, int itemIndex, T item)
        {
            if (m_Behaviour == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("SyncList not initialized");
                }
                return;
            }

            var uv = m_Behaviour.GetComponent <NetworkIdentity>();

            if (uv == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("SyncList no NetworkIdentity");
                }
                return;
            }

            if (!uv.isServer)
            {
                // object is not spawned yet, so no need to send updates.
                return;
            }


            // construct and send message
            SyncListMessage message = new SyncListMessage();

            message.netId        = uv.netId;
            message.syncListHash = m_CmdHash;

            NetworkWriter writer = new NetworkWriter();

            writer.Write((byte)op);
            writer.WritePackedUInt32((uint)itemIndex);
            SerializeItem(writer, item);

            message.payload = writer.ToArray();

            NetworkServer.SendByChannelToReady(uv.gameObject, (short)MsgType.SyncList, message, m_Behaviour.GetNetworkChannel());

#if UNITY_EDITOR
            UnityEditor.NetworkDetailStats.IncrementStat(
                UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
                (short)MsgType.SyncList, op.ToString(), 1);
#endif

            // ensure it is invoked on host
            if (m_Behaviour.isServer && m_Behaviour.isClient && m_Callback != null)
            {
                m_Callback.Invoke(op, itemIndex);
            }
        }