Пример #1
0
        void HandleGUIEvents(Event evt)
        {
            if (evt.rawType == EventType.KeyDown && evt.keyCode != KeyCode.None)
            {
                if (evt.keyCode == KeyCode.LeftShift || evt.keyCode == KeyCode.RightShift)
                {
                    shiftDown = true;
                }

                TouchInfo touch = _touches[0];
                touch.keyCode   = evt.keyCode;
                touch.modifiers = evt.modifiers;

                touch.UpdateEvent();
                DisplayObject f = this.focus;
                if (f != null)
                {
                    f.onKeyDown.BubbleCall(touch.evt);
                }
                else
                {
                    this.onKeyDown.Call(touch.evt);
                }
            }
            else if (evt.rawType == EventType.KeyUp)
            {
                if (evt.keyCode == KeyCode.LeftShift || evt.keyCode == KeyCode.RightShift)
                {
                    shiftDown = false;
                }

                TouchInfo touch = _touches[0];
                touch.modifiers = evt.modifiers;
            }
            else if (evt.type == EventType.scrollWheel)
            {
                if (_touchTarget != null)
                {
                    TouchInfo touch = _touches[0];
                    touch.mouseWheelDelta = (int)evt.delta.y;
                    touch.UpdateEvent();
                    _touchTarget.onMouseWheel.BubbleCall(touch.evt);
                }
            }
        }
Пример #2
0
        void MouseEvents(Vector2 mousePosition, TouchInfo touch, bool mouseLeftDown, bool mouseLeftUp, bool mouseRightDown, bool mouseRightUp)
        {
            bool hitTested = false;

            if (mousePosition.x >= 0 && mousePosition.y >= 0)
            {
                if (touch.x != mousePosition.x || touch.y != mousePosition.y)
                {
                    touchPosition = mousePosition;
                    touch.x       = mousePosition.x;
                    touch.y       = mousePosition.y;

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

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

                    if (touch.lastRollOver != _touchTarget)
                    {
                        HandleRollOver(touch);
                    }
                }
            }
            else
            {
                mousePosition = touchPosition;
            }

            if (mouseLeftDown)
            {
                if (!touch.began)
                {
                    touch.began = true;
                    _touchCount++;
                    touch.clickCancelled = false;
                    touch.downX          = touch.x;
                    touch.downY          = touch.y;

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

                    this.focus = _touchTarget;

                    if (_touchTarget != null)
                    {
                        touch.UpdateEvent();
                        _touchTarget.onTouchBegin.BubbleCall(touch.evt);
                    }
                }
            }
            if (mouseLeftUp)
            {
                if (touch.began)
                {
                    touch.began = false;
                    _touchCount--;

                    if (!hitTested)
                    {
                        _touchTarget = HitTest(mousePosition, 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)
                        {
                            if (ToolSet.RealtimeSinceStartup() - touch.lastClickTime < 0.35f)
                            {
                                if (touch.clickCount == 2)
                                {
                                    touch.clickCount = 1;
                                }
                                else
                                {
                                    touch.clickCount++;
                                }
                            }
                            else
                            {
                                touch.clickCount = 1;
                            }
                            touch.lastClickTime = ToolSet.RealtimeSinceStartup();
                            touch.UpdateEvent();
                            _touchTarget.onClick.BubbleCall(touch.evt);
                        }
                    }
                }
            }
            if (mouseRightDown)
            {
                if (!hitTested)
                {
                    _touchTarget = HitTest(mousePosition, true);
                    hitTested    = true;
                    touch.target = _touchTarget;
                }

                if (_touchTarget != null)
                {
                    touch.UpdateEvent();
                    _touchTarget.onRightClick.BubbleCall(touch.evt);
                }
            }
        }
Пример #3
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();
                }
            }
        }