示例#1
0
        public void ResetInputState()
        {
            for (int j = 0; j < 5; j++)
            {
                TouchInfo touch = _touches[j];
                touch.Reset();
            }

            if (!touchScreen)
            {
                _touches[0].touchId = 0;
            }
        }
示例#2
0
        void HandleTouchEvents()
        {
            for (int i = 0; i < Input.touchCount; ++i)
            {
                Touch uTouch = Input.GetTouch(i);

                if (uTouch.phase == TouchPhase.Stationary)
                {
                    continue;
                }

                bool    hitTested = false;
                Vector2 pos       = uTouch.position;
                pos.y = stageHeight - pos.y;
                TouchInfo touch = null;
                for (int j = 0; j < 5; j++)
                {
                    if (_touches[j].touchId == uTouch.fingerId)
                    {
                        touch = _touches[j];
                        break;
                    }

                    if (_touches[j].touchId == -1)
                    {
                        touch = _touches[j];
                    }
                }
                if (touch == null)
                {
                    continue;
                }

                touch.touchId = uTouch.fingerId;
                touchPosition = pos;

                if (touch.x != pos.x || touch.y != pos.y)
                {
                    touch.x = pos.x;
                    touch.y = pos.y;

                    _touchTarget = HitTest(pos, true);
                    hitTested    = true;
                    touch.target = _touchTarget;

                    touch.UpdateEvent();
                    onTouchMove.Call(touch.evt);

                    //no rollover/rollout on mobile
                }

                if (uTouch.phase == TouchPhase.Began)
                {
                    if (!touch.began)
                    {
                        touch.began = true;
                        _touchCount++;
                        touch.clickCancelled = false;
                        touch.downX          = touch.x;
                        touch.downY          = touch.y;

                        if (!hitTested)
                        {
                            _touchTarget = HitTest(pos, true);
                            hitTested    = true;
                            touch.target = _touchTarget;
                        }

                        this.focus = _touchTarget;

                        if (_touchTarget != null)
                        {
                            touch.UpdateEvent();
                            _touchTarget.onTouchBegin.BubbleCall(touch.evt);
                        }
                    }
                }
                else if (uTouch.phase == TouchPhase.Canceled || uTouch.phase == TouchPhase.Ended)
                {
                    if (touch.began)
                    {
                        touch.began = false;
                        _touchCount--;

                        if (!hitTested)
                        {
                            _touchTarget = HitTest(pos, true);
                            hitTested    = true;
                            touch.target = _touchTarget;
                        }

                        if (_touchTarget != null)
                        {
                            touch.UpdateEvent();
                            _touchTarget.onTouchEnd.BubbleCall(touch.evt);

                            if (!touch.clickCancelled && Mathf.Abs(touch.x - touch.downX) < 50 && Mathf.Abs(touch.y - touch.downY) < 50)
                            {
                                touch.clickCount = uTouch.tapCount;
                                touch.UpdateEvent();
                                _touchTarget.onClick.BubbleCall(touch.evt);
                            }
                        }
                    }

                    touch.Reset();
                }
            }
        }