Пример #1
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
                            }
                        }
                    }
                }
            }
        }
Пример #2
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
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Processes the message data according to the message header included in the data.
        /// </summary>
        /// <param name="msg">Message to process.</param>
        private static void processMessage(byte[] msg)
        {
            byte msgHeader = ObjectSerializer.deserializeByte(ref msg);

            switch (msgHeader)
            {
            case 0:
                processTransformMessage(msg, false);
                break;

            case 1:
                processTransformMessage(msg, true);
                break;

            case 2:
                processRigidbodyMessage(msg, false);
                break;

            case 3:
                processRigidbodyMessage(msg, true);
                break;

            case 4:
                processSetActiveMessage(msg, false);
                break;

            case 5:
                processSetActiveMessage(msg, true);
                break;

            case 6:
                processNetworkAuthorityMessage(msg, false);
                break;

            case 7:
                processNetworkAuthorityMessage(msg, true);
                break;

            case 8:
                processAddJointMessage(msg, false);
                break;

            case 9:
                processAddJointMessage(msg, true);
                break;

            case 10:
                processRemoveJointMessage(msg, false);
                break;

            case 11:
                processRemoveJointMessage(msg, true);
                break;

            case 12:
                processClientConnectionEventMessage(msg);
                break;

            case 13:
                processClientDisconnectionEventMessage(msg);
                break;

            case 14:
                processClientReconnectionEventMessage(msg);
                break;

            case 15:
                processClientIDMessage(msg);
                break;

            case 16:
                processClientReidentifiedMessage(msg);
                break;

            case 17:
                processBaseSyncVarMessage(msg, false);
                break;

            case 18:
                processBaseSyncVarMessage(msg, true);
                break;

            case 19:
                processColorSyncVarMessage(msg, false);
                break;

            case 20:
                processColorSyncVarMessage(msg, true);
                break;

            case 21:
                processGameObjectSyncVarMessage(msg, false);
                break;

            case 22:
                processGameObjectSyncVarMessage(msg, true);
                break;

            case 23:
                processQuaternionSyncVarMessage(msg, false);
                break;

            case 24:
                processQuaternionSyncVarMessage(msg, true);
                break;

            case 25:
                processVector2SyncVarMessage(msg, false);
                break;

            case 26:
                processVector2SyncVarMessage(msg, true);
                break;

            case 27:
                processVector3SyncVarMessage(msg, false);
                break;

            case 28:
                processVector3SyncVarMessage(msg, true);
                break;

            case 29:
                processNetworkIDRequestMessage(msg);
                break;

            case 30:
                processNetworkIDMessage(msg);
                break;

            case 31:
                processAvatarRequestMessage(msg, false);
                break;

            case 32:
                processAvatarRequestMessage(msg, true);
                break;

            case 33:
                processNetworkEventMessage(msg, true);
                break;

            case 34:
                processNetworkEventMessage(msg, false);
                break;

            default:
                processCustomMessage(msgHeader, msg);
                break;
            }
        }