Exemplo n.º 1
0
        private void onMouseDown(EventX e)
        {
            MouseEventX mouseEvent = e as MouseEventX;
            Touch       touch      = mouseEvent.touch;

            if (!mEnabled)
            {
                return;
            }

            if (touch.phase == TouchPhase.Began && !mIsDown)
            {
                mBackground = mDownState;
                addEventListener(MouseEventX.MOUSE_UP, onMouseUp);
                addEventListener(MouseEventX.MOUSE_LEAVE, onMouseLeave);

                mContents.scaleX = mContents.scaleY = mScaleWhenDown;
                mContents.x      = (1.0f - mScaleWhenDown) / 2.0f * mBackground.width;
                mContents.y      = (1.0f - mScaleWhenDown) / 2.0f * mBackground.height;
                mIsDown          = true;
                //Debug.Log( "mouse down" );
            }
        }
Exemplo n.º 2
0
        private void updateInput()
        {
            if (_stage == null)
            {
                return;
            }
            bool        isNew = false;
            MouseEventX mouseEvent;
            Event       currentEvent = Event.current;

            if (currentEvent != null && currentEvent.button == 0)
            {
                Vector2 t = currentEvent.mousePosition;
                mp.setTo(t.x, t.y);

                _collidingObject = _stage.hitTest(mp);
                isNew            = (_previousCollidingObject != _collidingObject);

                if (currentEvent.type == EventType.MouseDown)
                {
                    mouseEvent = new MouseEventX(MouseEventX.MOUSE_DOWN, mp);

                    if (_previousCollidingObject != null && isNew)
                    {
                        _previousCollidingObject.dispatchEvent(new MouseEventX(MouseEventX.MOUSE_UP, mp));
                    }

                    if (_collidingObject != null && isNew)
                    {
                        _collidingObject.dispatchEvent(mouseEvent);
                    }

                    _stage.dispatchEvent(mouseEvent);
                }
                else if (currentEvent.type == EventType.MouseUp)
                {
                    mouseEvent = new MouseEventX(MouseEventX.MOUSE_UP, mp);
                    if (_collidingObject != null && isNew)
                    {
                        _collidingObject.dispatchEvent(mouseEvent);
                    }
                    _stage.dispatchEvent(mouseEvent);
                }
                else if (currentEvent.type == EventType.mouseMove)
                {
                    mouseEvent = new MouseEventX(MouseEventX.MOUSE_MOVE, mp);

                    if (_collidingObject != null && isNew == false)
                    {
                        _collidingObject.dispatchEvent(mouseEvent);
                    }

                    _stage.dispatchEvent(mouseEvent);
                }



                if (_collidingObject != _previousCollidingObject)
                {
                    if (_previousCollidingObject != null)
                    {
                        _previousCollidingObject.dispatchEvent(new MouseEventX(MouseEventX.MOUSE_OUT, mp));
                    }
                    if (_collidingObject != null)
                    {
                        _collidingObject.dispatchEvent(new MouseEventX(MouseEventX.MOUSE_OVER, mp));
                    }
                }
                else if (_collidingObject != null)
                {
                    _collidingObject.dispatchEvent(new MouseEventX(MouseEventX.MOUSE_MOVE, mp));
                }

                _previousCollidingObject = _collidingObject;



                return;
            }

            //todo;
            int touchCount = Input.touchCount;

            if (touchCount < 1)
            {
                if (_previousCollidingObject != null)
                {
                    _previousCollidingObject.dispatchEvent(new MouseEventX(MouseEventX.MOUSE_UP, null));
                    _previousCollidingObject = null;
                }
                return;
            }
            Touch touch = Input.touches[0];

            mp.setTo(touch.position.x, touch.position.y);
            _collidingObject = stage.hitTest(mp);

            isNew = (_previousCollidingObject != _collidingObject);

            switch (touch.phase)
            {
            case TouchPhase.Began:

                if (_previousCollidingObject != null && isNew)
                {
                    _previousCollidingObject.dispatchEvent(new MouseEventX(MouseEventX.MOUSE_UP, mp));
                }

                if (_collidingObject != null && isNew)
                {
                    _collidingObject.dispatchEvent(new MouseEventX(MouseEventX.MOUSE_DOWN, mp));
                }
                break;


            case TouchPhase.Canceled:
            case TouchPhase.Ended:

                if (_previousCollidingObject != null)
                {
                    _previousCollidingObject.dispatchEvent(new MouseEventX(MouseEventX.MOUSE_UP, mp));
                }
                break;

            case TouchPhase.Moved:

                if (_collidingObject != null && isNew == false)
                {
                    _collidingObject.dispatchEvent(new MouseEventX(MouseEventX.MOUSE_MOVE, mp));
                }

                break;
            }


            _previousCollidingObject = _collidingObject;
        }
Exemplo n.º 3
0
        public void update()
        {
            if ((Input.anyKey || currentDownKeys.Count > 0) && (eventDownDictonary.Count > 0 || eventUpDictonary.Count > 0))
            {
                //Debug.Log(Input.anyKey+":"+Input.anyKeyDown);
                updateKey();
                return;
            }


            bool        isNew = false;
            MouseEventX mouseEvent;
            Event       currentEvent = Event.current;

            if (currentEvent != null && currentEvent.button == 0)
            {
                Vector2 t = currentEvent.mousePosition;
                mp.setTo(t.x, t.y);

                _collidingObject = checkPicker(t);
                isNew            = (_previousCollidingObject != _collidingObject);

                if (currentEvent.type == EventType.MouseDown)
                {
                    mouseEvent = new MouseEventX(MouseEventX.MOUSE_DOWN, mp);

                    if (_previousCollidingObject != null && isNew)
                    {
                        _previousCollidingObject.BroadcastMessage("dispatchEvent",
                                                                  new MouseEventX(MouseEventX.MOUSE_UP, mp));
                    }

                    if (_collidingObject != null && isNew)
                    {
                        _collidingObject.BroadcastMessage("dispatchEvent", mouseEvent);
                    }

                    this.dispatchEvent(mouseEvent);
                }
                else if (currentEvent.type == EventType.MouseUp)
                {
                    mouseEvent = new MouseEventX(MouseEventX.MOUSE_UP, mp);
                    if (_collidingObject != null && isNew)
                    {
                        _collidingObject.BroadcastMessage("dispatchEvent", mouseEvent);
                    }
                    this.dispatchEvent(mouseEvent);
                }
                else if (currentEvent.type == EventType.mouseMove)
                {
                    mouseEvent = new MouseEventX(MouseEventX.MOUSE_MOVE, mp);

                    if (_collidingObject != null && isNew == false)
                    {
                        _collidingObject.BroadcastMessage("dispatchEvent", mouseEvent);
                    }

                    this.dispatchEvent(mouseEvent);
                }

                if (_collidingObject != _previousCollidingObject)
                {
                    if (_previousCollidingObject != null)
                    {
                        _previousCollidingObject.BroadcastMessage("dispatchEvent",
                                                                  new MouseEventX(MouseEventX.MOUSE_OUT, mp));
                    }
                    if (_collidingObject != null)
                    {
                        _collidingObject.BroadcastMessage("dispatchEvent", new MouseEventX(MouseEventX.MOUSE_OVER, mp));
                    }
                }
                else if (_collidingObject != null)
                {
                    _collidingObject.BroadcastMessage("dispatchEvent", new MouseEventX(MouseEventX.MOUSE_MOVE, mp));
                }

                _previousCollidingObject = _collidingObject;

                return;
            }

            int touchCount = Input.touchCount;

            if (touchCount < 1)
            {
                if (_previousCollidingObject != null)
                {
                    _previousCollidingObject.BroadcastMessage("dispatchEvent", MouseEventX.MOUSE_UP);
                    _previousCollidingObject = null;
                }
                return;
            }

            Touch touch = Input.touches[0];

            mp.setTo(touch.position.x, touch.position.y);
            _collidingObject = checkPicker(Input.touches[0].position);
            isNew            = (_previousCollidingObject != _collidingObject);

            switch (touch.phase)
            {
            case TouchPhase.Began:

                if (_previousCollidingObject != null && isNew)
                {
                    _previousCollidingObject.BroadcastMessage("dispatchEvent", new MouseEventX(MouseEventX.MOUSE_UP, mp));
                }

                if (_collidingObject != null && isNew)
                {
                    _collidingObject.BroadcastMessage("dispatchEvent", new MouseEventX(MouseEventX.MOUSE_DOWN, mp));
                }
                break;


            case TouchPhase.Canceled:
            case TouchPhase.Ended:

                if (_previousCollidingObject != null)
                {
                    _previousCollidingObject.BroadcastMessage("dispatchEvent", new MouseEventX(MouseEventX.MOUSE_UP, mp));
                }
                break;

            case TouchPhase.Moved:

                if (_collidingObject != null && isNew == false)
                {
                    _collidingObject.BroadcastMessage("dispatchEvent", new MouseEventX(MouseEventX.MOUSE_MOVE, mp));
                }

                break;
            }

            _previousCollidingObject = _collidingObject;
        }