Exemple #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);
            }
        }