/**
         * Handles messages receieved from this object's subscription based on the exchange name,
         * exchange type, and routing key used. You could also write an anonymous delegate in line
         * when creating the subscription like: (received) => { Debug.Log(received.Message.Body.Length); }
         */
        void HandleExchangeMessageReceived(AmqpExchangeReceivedMessage received)
        {
            // First convert the message's body, which is a byte array, into a string for parsing the JSON
            var receivedJson = System.Text.Encoding.UTF8.GetString(received.Message.Body);

            Debug.Log(receivedJson);

            /**
             *  Parse the JSON message
             *  This example uses the SimpleJSON parser which is included in the AMQP library.
             *  You can find out more about this parser here: http://wiki.unity3d.com/index.php/SimpleJSON
             */

            // If this starts with a bracket, it's an array of messages, so decode separately
            if (receivedJson.StartsWith("["))
            {
                var msgList = JSON.Parse(receivedJson).AsArray;

                for (var i = 0; i < msgList.Count; i++)
                {
                    var msg = msgList[i];
                    UpdateObject(msg);
                }
            }

            // Otherwise it's an individual message so decode individually
            else
            {
                var msg = JSON.Parse(receivedJson);
                UpdateObject(msg);
            }
        }
Exemple #2
0
        /**
         * Handles messages receieved from this object's subscription based on the exchange name,
         * exchange type, and routing key used. You could also write an anonymous delegate in line
         * when creating the subscription like: (received) => { Debug.Log(received.Message.Body.Length); }
         */

        void HandleInputMessageReceived(AmqpExchangeReceivedMessage received)
        {
            // First convert the message's body, which is a byte array, into a string for parsing the JSON
            var receivedJson = System.Text.Encoding.UTF8.GetString(received.Message.Body);

            // Log if enabled
            if (DebugLogMessages)
            {
                Debug.LogFormat("AMQP message received for {0}{1} => {2}", name,
                                !string.IsNullOrEmpty(IdFilter) ? " id:" + IdFilter : null, receivedJson);
            }

            /**
             *  Parse the JSON message
             *  This example uses the SimpleJSON parser which is included in the AMQP library.
             *  You can find out more about this parser here: http://wiki.unity3d.com/index.php/SimpleJSON
             */
            var msg = CymaticLabs.Unity3D.Amqp.SimpleJSON.JSON.Parse(receivedJson);

            // Get the message ID filter, if any
            var id = msg["id"] != null ? msg["id"].Value : null;

            // If an ID exists but it doesn't match the current ID filter then ignore this message
            if (!string.IsNullOrEmpty(IdFilter) && IdFilter != id)
            {
                if (DebugLogMessages)
                {
                    Debug.LogFormat("AMQP message ignored for {0} id:{1} != {2}", name, IdFilter, id);
                }

                return;
            }


            {
                // If the property exists use its value, otherwise just use the current value
                var objPos = (Vector2)transform.position;
                var posX   = msg["posX"] != null ? msg["posX"].AsFloat : objPos.x;
                var posY   = msg["posY"] != null ? msg["posY"].AsFloat : objPos.y;
                //var posZ = msg["posZ"] != null ? msg["posZ"].AsFloat : objPos.z;
                Vector2 destVector2 = new Vector2(posX, posY);
                var     movePulse   = destVector2 - objPos;
                // Update with new values
                CentralBus.MotorMove.Invoke(movePulse);


                //transform.position = new Vector3(posX, posY, posZ);
            }
        }
Exemple #3
0
        /**
         * Handles messages receieved from this object's subscription based on the exchange name,
         * exchange type, and routing key used. You could also write an anonymous delegate in line
         * when creating the subscription like: (received) => { Debug.Log(received.Message.Body.Length); }
         */

        void HandleInputMessageReceived(AmqpExchangeReceivedMessage received)
        {
            // First convert the message's body, which is a byte array, into a string for parsing the JSON
            var receivedJson = System.Text.Encoding.UTF8.GetString(received.Message.Body);

            // Log if enabled
            if (DebugLogMessages)
            {
                Debug.LogFormat("AMQP message received for {0}{1} => {2}", name,
                                !string.IsNullOrEmpty(IdFilter) ? " id:" + IdFilter : null, receivedJson);
            }

            /**
             *  Parse the JSON message
             *  This example uses the SimpleJSON parser which is included in the AMQP library.
             *  You can find out more about this parser here: http://wiki.unity3d.com/index.php/SimpleJSON
             */
            var msg = CymaticLabs.Unity3D.Amqp.SimpleJSON.JSON.Parse(receivedJson);

            CentralBus.BrainRadio.Invoke(msg);
        }
        /**
         * Handles messages receieved from this object's subscription based on the exchange name,
         * exchange type, and routing key used. You could also write an anonymous delegate in line
         * when creating the subscription like: (received) => { Debug.Log(received.Message.Body.Length); }
         */
        void HandleExchangeMessageReceived(AmqpExchangeReceivedMessage received)
        {
            // First convert the message's body, which is a byte array, into a string for parsing the JSON
            var receivedJson = System.Text.Encoding.UTF8.GetString(received.Message.Body);

            // Log if enabled
            if (DebugLogMessages)
            {
                Debug.LogFormat("AMQP message received for {0}{1} => {2}", name, !string.IsNullOrEmpty(IdFilter) ? " id:" + IdFilter : null, receivedJson);
            }

            /**
             *  Parse the JSON message
             *  This example uses the SimpleJSON parser which is included in the AMQP library.
             *  You can find out more about this parser here: http://wiki.unity3d.com/index.php/SimpleJSON
             */
            var msg = CymaticLabs.Unity3D.Amqp.SimpleJSON.JSON.Parse(receivedJson);

            // Get the message ID filter, if any
            var id = msg["id"] != null ? msg["id"].Value : null;

            // If an ID exists but it doesn't match the current ID filter then ignore this message
            if (!string.IsNullOrEmpty(IdFilter) && IdFilter != id)
            {
                if (DebugLogMessages)
                {
                    Debug.LogFormat("AMQP message ignored for {0} id:{1} != {2}", name, IdFilter, id);
                }

                return;
            }

            if (UpdatePosition)
            {
                // If the property exists use its value, otherwise just use the current value
                var objPos = UpdateInWorldSpace ? transform.position : transform.localPosition;
                var posX   = msg["posX"] != null ? msg["posX"].AsFloat : objPos.x;
                var posY   = msg["posY"] != null ? msg["posY"].AsFloat : objPos.y;
                var posZ   = msg["posZ"] != null ? msg["posZ"].AsFloat : objPos.z;

                // Update with new values
                if (UpdateInWorldSpace)
                {
                    transform.position = new Vector3(posX, posY, posZ);
                }
                else
                {
                    transform.localPosition = new Vector3(posX, posY, posZ);
                }
            }

            if (UpdateRotation)
            {
                // If the property exists use its value, otherwise just use the current value
                var objRot = UpdateInWorldSpace ? transform.eulerAngles : transform.localEulerAngles;
                var rotX   = msg["rotX"] != null ? msg["rotX"].AsFloat : objRot.x;
                var rotY   = msg["rotY"] != null ? msg["rotY"].AsFloat : objRot.y;
                var rotZ   = msg["rotZ"] != null ? msg["rotZ"].AsFloat : objRot.z;

                // Update with new values
                if (UpdateInWorldSpace)
                {
                    transform.eulerAngles = new Vector3(rotX, rotY, rotZ);
                }
                else
                {
                    transform.localEulerAngles = new Vector3(rotX, rotY, rotZ);
                }
            }

            if (UpdateScale)
            {
                // If the property exists use its value, otherwise just use the current value
                var scaleX = msg["sclX"] != null ? msg["sclX"].AsFloat : transform.localScale.x;
                var scaleY = msg["sclY"] != null ? msg["sclY"].AsFloat : transform.localScale.y;
                var scaleZ = msg["sclZ"] != null ? msg["sclZ"].AsFloat : transform.localScale.z;

                // Update with new values
                transform.localScale = new Vector3(scaleX, scaleY, scaleZ);
            }
        }