Пример #1
0
    void ReadBuildingsState(NetworkMessage message)
    {
        if (isServer)
        {
            return;
        }

        BuildingUpdateMessage msg = message.ReadMessage <BuildingUpdateMessage>();

        if (lastReadBuildingsState > msg.number)
        {
            return;
        }
        else
        {
            lastReadBuildingsState = msg.number;
        }

        foreach (BuildingUpdateMessage_RB_DATA data in msg.rigidbodys)
        {
            Rigidbody rb = BuildingCollision.Buildings[data.buildingIndex].Rigidbodies[data.rigidbodyIndex];

            BuildingCollision.Buildings[data.buildingIndex].targetPos[data.rigidbodyIndex] = data.position;
            BuildingCollision.Buildings[data.buildingIndex].targetRot[data.rigidbodyIndex] = data.rotation;

            rb.velocity = data.velocity;
        }
    }
Пример #2
0
    void SendBuildingsState()
    {
        BuildingUpdateMessage msg = new BuildingUpdateMessage();

        for (int i = 0; i < BuildingCollision.Buildings.Count; i++)
        {
            int j = -1;

            if (BuildingCollision.Buildings[i].Triggered)
            {
                continue;
            }

            foreach (Rigidbody rigidbody in BuildingCollision.Buildings[i].Rigidbodies)
            {
                j++;

                if (rigidbody.IsSleeping())
                {
                    continue;
                }

                BuildingUpdateMessage_RB_DATA data = new BuildingUpdateMessage_RB_DATA();

                data.buildingIndex  = i;
                data.rigidbodyIndex = j;
                data.position       = rigidbody.transform.position;
                data.rotation       = rigidbody.transform.rotation;
                data.velocity       = rigidbody.velocity;
                msg.rigidbodys.Add(data);

                if (msg.rigidbodys.Count > 20)
                {
                    NetworkServer.SendUnreliableToAll(NetworkMessages.BuildingUpdate, msg);
                    msg = new BuildingUpdateMessage();
                }
            }
        }
        NetworkServer.SendUnreliableToAll(NetworkMessages.BuildingUpdate, msg);
    }