Exemplo n.º 1
0
    // Broadcast sync data
    void BroadcastSync()
    {
        if (!owned)
        {
            return;
        }
        MemoryStream stream    = new MemoryStream();
        BinaryWriter binWriter = new BinaryWriter(stream);

        // Get the data
        if (getDataFunction != null)
        {
            getDataFunction(ref binWriter);
        }

        // Send this data to all of the other objects with my network id
        byte[] dataArray        = stream.ToArray();
        bool   arrayDataChanged = !dataArray.Compare(tData);

        position = transform.localPosition;
        rotation = transform.localRotation;

        // If the position has changed, do a full update
        if (position != tPosition || rotation != tRotation)
        {
            tPosition = position;
            tRotation = rotation;
            if (inAreaOnly)
            {
                clientNet.SyncNetworkData(networkId, UCNetwork.MessageReceiver.OtherClientsInArea, deliveryMethod, dataArray, position, rotation);
            }
            else
            {
                clientNet.SyncNetworkData(networkId, UCNetwork.MessageReceiver.OtherClients, deliveryMethod, dataArray, position, rotation);
            }
            // If the data has changed, and the position hasn't, do a lite update.
        }
        else if (arrayDataChanged)
        {
            tData = dataArray;
            if (inAreaOnly)
            {
                clientNet.LiteSyncNetworkData(networkId, UCNetwork.MessageReceiver.OtherClientsInArea, deliveryMethod, dataArray);
            }
            else
            {
                clientNet.LiteSyncNetworkData(networkId, UCNetwork.MessageReceiver.OtherClients, deliveryMethod, dataArray);
            }
        }
        else
        {
            //Debug.Log("Sending no update with positions: " + position + " " + tPosition);
        }
        // If nothing has changed, don't send any updates
    }