コード例 #1
0
 public void CancelClick(int touchId)
 {
     for (int j = 0; j < 5; j++)
     {
         TouchInfo touch = _touches[j];
         if (touch.touchId == touchId)
         {
             touch.clickCancelled = true;
         }
     }
 }
コード例 #2
0
        public void ResetInputState()
        {
            for (int j = 0; j < 5; j++)
            {
                TouchInfo touch = _touches[j];
                touch.Reset();
            }

            if (!touchScreen)
            {
                _touches[0].touchId = 0;
            }
        }
コード例 #3
0
        public void EditorHandleOnGUI()
        {
            HandleGUIEvents(Event.current);
            Vector2   mousePosition = Event.current.mousePosition;
            TouchInfo touch         = _touches[0];

            MouseEvents(mousePosition, touch,
                        Event.current.button == 0 && Event.current.type == EventType.MouseDown,
                        Event.current.button == 0 && Event.current.type == EventType.mouseUp,
                        Event.current.button == 1 && Event.current.type == EventType.MouseDown,
                        Event.current.button == 1 && Event.current.type == EventType.mouseUp);
            HandleRender();
        }
コード例 #4
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);
                }
            }
        }
コード例 #5
0
        public Vector2 GetTouchPosition(int touchId)
        {
            if (touchId < 0)
            {
                return(touchPosition);
            }

            for (int j = 0; j < 5; j++)
            {
                TouchInfo touch = _touches[j];
                if (touch.touchId == touchId)
                {
                    return(new Vector2(touch.x, touch.y));
                }
            }

            return(touchPosition);
        }
コード例 #6
0
        public Stage()
            : base()
        {
            if (support == null)
            {
                support = new RenderSupport();
            }
            _stageWidth  = Screen.width;
            _stageHeight = Screen.height;

            _lastMousePos     = Vector2.zero;
            _lastMouseDownPos = Vector2.zero;
            _focused          = this;

            //
            _lastHandleInputFrame = -1;

            if (Application.isMobilePlatform)
            {
                touchScreen = true;
            }

            _touches = new TouchInfo[5];
            for (int i = 0; i < _touches.Length; i++)
            {
                _touches[i] = new TouchInfo();
            }

            if (!touchScreen)
            {
                _touches[0].touchId = 0;
            }

            _rollOutChain  = new List <DisplayObject>();
            _rollOverChain = new List <DisplayObject>();

            onStageResized = new EventListener(this, "onStageResized");
            onTouchMove    = new EventListener(this, "onTouchMove");
        }
コード例 #7
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);
                }
            }
        }
コード例 #8
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();
                }
            }
        }