Exemple #1
0
        private static void processRemoveJointMessage(byte[] msg, bool clientMessage)
        {
            short jointParentID = ObjectSerializer.deserializeShort(ref msg);

            if (NetworkEntityManager.Instance.findComponent(jointParentID, out NetworkIdentity jointParent))
            {
                byte[] removeJointMsg = null;
                bool   forwardMessage = clientMessage && ServerBehaviour.Instance; //Should the message be forwarded?

                byte jointType = ObjectSerializer.deserializeByte(ref msg);
                switch (jointType)
                {
                case 0:
                    if (NetworkEntityManager.Instance.findComponent(jointParentID, out FixedJoint fixedJoint, true))
                    {
                        Object.Destroy(fixedJoint);     //Destroy the joint
                    }
                    if (forwardMessage)
                    {
                        removeJointMsg = MessageFactory.createRemoveJointMessage <FixedJoint>(jointParent);
                    }
                    break;

                case 1:
                    if (NetworkEntityManager.Instance.findComponent(jointParentID, out HingeJoint hingeJoint, true))
                    {
                        Object.Destroy(hingeJoint);     //Destroy the joint
                    }
                    if (forwardMessage)
                    {
                        removeJointMsg = MessageFactory.createRemoveJointMessage <HingeJoint>(jointParent);
                    }
                    break;

                case 2:
                    if (NetworkEntityManager.Instance.findComponent(jointParentID, out SpringJoint springJoint, true))
                    {
                        Object.Destroy(springJoint);     //Destroy the joint
                    }
                    if (forwardMessage)
                    {
                        removeJointMsg = MessageFactory.createRemoveJointMessage <SpringJoint>(jointParent);
                    }
                    break;

                case 3:
                    if (NetworkEntityManager.Instance.findComponent(jointParentID, out ConfigurableJoint configurableJoint, true))
                    {
                        Object.Destroy(configurableJoint);     //Destroy the joint
                    }
                    if (forwardMessage)
                    {
                        removeJointMsg = MessageFactory.createRemoveJointMessage <ConfigurableJoint>(jointParent);
                    }
                    break;

                case 4:
                    if (NetworkEntityManager.Instance.findComponent(jointParentID, out CharacterJoint characterJoint, true))
                    {
                        Object.Destroy(characterJoint);     //Destroy the joint
                    }
                    if (forwardMessage)
                    {
                        removeJointMsg = MessageFactory.createRemoveJointMessage <CharacterJoint>(jointParent);
                    }
                    break;
                }

                //Message was sent from a client, now being processed on the server
                if (forwardMessage)
                {
                    short clientID = ObjectSerializer.deserializeShort(ref msg);          //Client who sent the message
                    ServerBehaviour.Instance.sendMessage(removeJointMsg, clientID, true); //Forward to all clients but the sender
                }
            }
        }
Exemple #2
0
        private static void processAddJointMessage(byte[] msg, bool clientMessage)
        {
            short jointParentID = ObjectSerializer.deserializeShort(ref msg);

            if (NetworkEntityManager.Instance.findComponent(jointParentID, out NetworkIdentity jointParent))
            {
                short connectedBodyID = ObjectSerializer.deserializeShort(ref msg);

                if (connectedBodyID == -2)                                             //No connected body
                {
                    byte[] addJointMsg    = null;                                      //Message to forward to other clients if this is a client message
                    bool   forwardMessage = clientMessage && ServerBehaviour.Instance; //Should the message be forwarded?

                    byte jointType = ObjectSerializer.deserializeByte(ref msg);
                    switch (jointType)
                    {
                    case 0:
                        jointParent.gameObject.AddComponent <FixedJoint>();

                        if (forwardMessage)
                        {
                            addJointMsg = MessageFactory.createAddJointMessage <FixedJoint>(jointParent, null);
                        }
                        break;

                    case 1:
                        jointParent.gameObject.AddComponent <HingeJoint>();

                        if (forwardMessage)
                        {
                            addJointMsg = MessageFactory.createAddJointMessage <HingeJoint>(jointParent, null);
                        }
                        break;

                    case 2:
                        jointParent.gameObject.AddComponent <SpringJoint>();

                        if (forwardMessage)
                        {
                            addJointMsg = MessageFactory.createAddJointMessage <SpringJoint>(jointParent, null);
                        }
                        break;

                    case 3:
                        jointParent.gameObject.AddComponent <ConfigurableJoint>();

                        if (forwardMessage)
                        {
                            addJointMsg = MessageFactory.createAddJointMessage <ConfigurableJoint>(jointParent, null);
                        }
                        break;

                    case 4:
                        jointParent.gameObject.AddComponent <CharacterJoint>();

                        if (forwardMessage)
                        {
                            addJointMsg = MessageFactory.createAddJointMessage <CharacterJoint>(jointParent, null);
                        }
                        break;
                    }

                    //Message was sent from a client, now being processed on the server
                    if (forwardMessage)
                    {
                        short clientID = ObjectSerializer.deserializeShort(ref msg);       //Client who sent the message
                        ServerBehaviour.Instance.sendMessage(addJointMsg, clientID, true); //Forward to all clients but the sender
                    }
                }
                else //Connected body
                {
                    if (NetworkEntityManager.Instance.findComponent(connectedBodyID, out NetworkIdentity connectedBody))
                    {
                        if (NetworkEntityManager.Instance.findComponent(connectedBodyID, out Rigidbody connectedBodyRb))
                        {
                            byte[] addJointMsg    = null;                                      //Message to forward to other clients if this is a client message
                            bool   forwardMessage = clientMessage && ServerBehaviour.Instance; //Should the message be forwarded?

                            byte jointType = ObjectSerializer.deserializeByte(ref msg);
                            switch (jointType)
                            {
                            case 0:
                                jointParent.gameObject.AddComponent <FixedJoint>().connectedBody = connectedBodyRb;

                                if (forwardMessage)
                                {
                                    addJointMsg = MessageFactory.createAddJointMessage <FixedJoint>(jointParent, connectedBody);
                                }
                                break;

                            case 1:
                                jointParent.gameObject.AddComponent <HingeJoint>().connectedBody = connectedBodyRb;

                                if (forwardMessage)
                                {
                                    addJointMsg = MessageFactory.createAddJointMessage <HingeJoint>(jointParent, connectedBody);
                                }
                                break;

                            case 2:
                                jointParent.gameObject.AddComponent <SpringJoint>().connectedBody = connectedBodyRb;

                                if (forwardMessage)
                                {
                                    addJointMsg = MessageFactory.createAddJointMessage <SpringJoint>(jointParent, connectedBody);
                                }
                                break;

                            case 3:
                                jointParent.gameObject.AddComponent <ConfigurableJoint>().connectedBody = connectedBodyRb;

                                if (forwardMessage)
                                {
                                    addJointMsg = MessageFactory.createAddJointMessage <ConfigurableJoint>(jointParent, connectedBody);
                                }
                                break;

                            case 4:
                                jointParent.gameObject.AddComponent <CharacterJoint>().connectedBody = connectedBodyRb;

                                if (forwardMessage)
                                {
                                    addJointMsg = MessageFactory.createAddJointMessage <CharacterJoint>(jointParent, connectedBody);
                                }
                                break;
                            }

                            //Message was sent from a client, now being processed on the server
                            if (forwardMessage)
                            {
                                short clientID = ObjectSerializer.deserializeShort(ref msg);       //Client who sent the message
                                ServerBehaviour.Instance.sendMessage(addJointMsg, clientID, true); //Forward to all clients but the sender
                            }
                        }
                    }
                }
            }
        }