Пример #1
0
        // Update is called once per frame
        void Update()
        {
            //byte[] msg;

            bsonObj = null;

            /* Get the first incoming message */
            if (bsonListener != null)
            {
                bsonObj = bsonListener.Receive();
            }

            while (bsonObj != null)
            {
                this.bsonParser.ParseBSON(bsonObj);
                try {
                    //Debug.Log (bsonObj["ipad"]["type"].stringValue);
                    if (bsonObj["ipad"]["type"].stringValue == "up")
                    {
                        gameObject.renderer.material.color = Color.red;
                    }
                    else if (bsonObj["ipad"]["type"].stringValue == "down")
                    {
                        gameObject.renderer.material.color = Color.green;
                    }
                    else if (bsonObj["ipad"]["type"].stringValue == "move")
                    {
                        //Debug.Log ("MOVE " + bsonObj["ipad"]["dist"][0]);
                        float dx = (float)bsonObj["ipad"]["dist"][0];
                        float dy = (float)bsonObj["ipad"]["dist"][1] * -1.0f;
                        float newX;
                        float newY;
                        newX = gameObject.transform.position.x + (dx * xSensitivity);
                        newY = gameObject.transform.position.y + (dy * ySensitivity);
                        if (constrainX)
                        {
                            if (wrapX)
                            {
                                newX = nfmod(newX, 1.0f);
                            }
                            else
                            {
                                newX = Mathf.Clamp(newX, 0.0f, 1.0f);
                            }
                        }

                        if (constrainY)
                        {
                            if (wrapY)
                            {
                                newY = nfmod(newY, 1.0f);
                            }
                            else
                            {
                                newY = Mathf.Clamp(newY, 0.0f, 1.0f);
                            }
                        }
                        gameObject.transform.position = new Vector3(newX, newY, 0);
                    }
                } catch (KeyNotFoundException) {
                    //unimplemented message.
                }

                /* Get the next message */
                bsonObj = bsonListener.Receive();
            }

                #if NO_CLUSTER
            while (this.bsonParser.messageQueue.Count > 0)
            {
                IiPadInput ipi = this.bsonParser.messageQueue.Dequeue();
                if (ipi.inputType == InputType.Tap && this.eh != null)
                {
                    this.eh.handleTap();
                }
            }
                #else
            if (icCluster.isMaster())
            {
                this.iPadTapped.SetValue(false);                 //always set to false at end of frame.
            }
            if (icCluster.isMaster())
            {
                while (this.bsonParser.messageQueue.Count > 0)
                {
                    IiPadInput ipi = this.bsonParser.messageQueue.Dequeue();
                    if (ipi.inputType == InputType.Tap && this.eh != null)
                    {
                        this.iPadTapped.SetValue(true);
                    }
                }
            }

            bool tapped = this.iPadTapped.GetValue();
            if (tapped)
            {
                this.eh.handleTap();
            }
                #endif
        }