Esempio n. 1
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.SendToReady(uv.gameObject, (short)MsgType.SyncList, message);

            // ensure it is invoked on host
            if (m_Behaviour.isServer && m_Behaviour.isClient && m_Callback != null)
            {
                m_Callback.Invoke(op, itemIndex);
            }
        }
Esempio n. 2
0
        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);
                }
            }
        }