Ejemplo n.º 1
0
        private bool GetMouseInput()
        {
            if (Input.GetMouseButtonDown(0))
            {
                _startPressPos = Input.mousePosition;
                _currPressPos  = _startPressPos;
                _isSwipeEnded  = false;
                TouchBegan?.Invoke(_startPressPos);
            }
            else if (Input.GetMouseButtonUp(0))
            {
                _endPressPos  = Input.mousePosition;
                _isSwipeEnded = true;
                TouchEnd?.Invoke(_endPressPos);

                return(true);
            }
            else if (Input.GetMouseButton(0))
            {
                _lastPressPos = _currPressPos;
                _currPressPos = Input.mousePosition;
                PointerDown?.Invoke(_currPressPos);

                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public static Task <bool> JsTouchEnd(TouchEvent @event)
        {
            if (@event is object)
            {
                TouchEnd?.Invoke(null, @event);
            }

            return(Task.FromResult(true));
        }
Ejemplo n.º 3
0
        private void SetEvent(Touch input)
        {
            firstTouchTime += input.deltaTime;

            OneTouchEvents?.Invoke(input.position, input.deltaPosition);

            if (input.phase == TouchPhase.Ended)
            {
                TouchEnd?.Invoke(input.deltaPosition, firstTouchTime);

                if (firstTouchTime > 0.1 && firstTouchTime < 0.3)
                {
                    OneFingerTap?.Invoke(input.position);
                }

                firstTouchTime  = 0;
                secondTouchTime = 0;
            }
        }
Ejemplo n.º 4
0
        private void Update()
        {
            bool touchInProgress = currentTouchPhase == TouchPhase.Moved || currentTouchPhase == TouchPhase.Stationary;

            touchPosition = Input.mousePosition;
            if (touchInProgress || boundRect.Contains(touchPosition.Value))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    currentTouchPhase = TouchPhase.Began;
                    TouchStart?.Invoke(currentTouchPhase, touchPosition.Value);
                }

                if (Input.GetMouseButton(0))
                {
                    if (!lastTouchPosition.HasValue)
                    {
                        lastTouchPosition = touchPosition.Value;
                    }

                    TouchDelta        = (touchPosition.Value - lastTouchPosition.Value) / scaleFactor;
                    lastTouchPosition = touchPosition.Value;

                    if (TouchDelta.magnitude > 0)
                    {
                        currentTouchPhase = TouchPhase.Moved;
                        TouchMove?.Invoke(currentTouchPhase, TouchDelta);
                    }
                    else
                    {
                        currentTouchPhase = TouchPhase.Stationary;
                        TouchStationary?.Invoke(currentTouchPhase, touchPosition.Value);
                    }
                }

                if (Input.GetMouseButtonUp(0))
                {
                    lastTouchPosition = null;
                    currentTouchPhase = TouchPhase.Ended;
                    TouchEnd?.Invoke(currentTouchPhase, touchPosition.Value);
                }
            }
        }
Ejemplo n.º 5
0
        private void FireTouchEvent(Touch i_touch, Vector2 i_startPos = default)
        {
            switch (i_touch.phase)
            {
            case TouchPhase.Began:
                TouchStart?.Invoke(i_touch, i_touch.position);
                break;

            case TouchPhase.Moved:
                TouchMove?.Invoke(i_touch, i_touch.position, i_touch.position - i_startPos);
                break;

            case TouchPhase.Ended:
                TouchEnd?.Invoke(i_touch);
                startPosByTouch.Remove(i_touch);
                allTouches.Remove(i_touch);
                break;
            }
        }
Ejemplo n.º 6
0
        private void SetEvent(Touch input1, Touch input2)
        {
            TwoTouchEvents?.Invoke(input1.position, input1.deltaPosition, input2.position, input2.deltaPosition);

            firstTouchTime  += input1.deltaTime;
            secondTouchTime += input2.deltaTime;

            if (input1.phase == TouchPhase.Ended && input2.phase == TouchPhase.Ended)
            {
                TouchEnd?.Invoke(input1.deltaPosition, firstTouchTime);

                if ((firstTouchTime > 0.1 && firstTouchTime < 0.3) ||
                    (secondTouchTime > 0.1 && secondTouchTime < 0.3))
                {
                    TwoFingerTap?.Invoke(input1.position);
                }

                firstTouchTime  = 0;
                secondTouchTime = 0;
            }
        }
Ejemplo n.º 7
0
        private bool GetTouchInput()
        {
            if (Input.touches.Length > 0)
            {
                var touch = Input.GetTouch(0);
                switch (touch.phase)
                {
                case TouchPhase.Began:
                    _startPressPos = touch.position;
                    _currPressPos  = _startPressPos;
                    _isSwipeEnded  = false;
                    TouchBegan?.Invoke(touch.position);

                    break;

                case TouchPhase.Ended:
                case TouchPhase.Canceled:
                    _endPressPos  = touch.position;
                    _isSwipeEnded = true;

                    TouchEnd?.Invoke(touch.position);

                    return(true);

                case TouchPhase.Moved:
                case TouchPhase.Stationary:
                    _lastPressPos = _currPressPos;
                    _currPressPos = touch.position;

                    PointerDown?.Invoke(touch.position);

                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 8
0
 public override void OnLevelEnd()
 {
     if (TouchStart != null)
     {
         foreach (TouchStartHandler d in TouchStart.GetInvocationList())
         {
             TouchStart -= (TouchStartHandler)d;
         }
     }
     if (TouchMove != null)
     {
         foreach (TouchMoveHandler d in TouchMove.GetInvocationList())
         {
             TouchMove -= (TouchMoveHandler)d;
         }
     }
     if (TouchEnd != null)
     {
         foreach (TouchEndHandler d in TouchEnd.GetInvocationList())
         {
             TouchEnd -= (TouchEndHandler)d;
         }
     }
 }
Ejemplo n.º 9
0
 // Use this for initialization
 void Start()
 {
     OnSwipe       += ((Vector3 position) => { });
     OnTouchEnd    += (() => { });
     curEventSystem = EventSystem.current;
 }
Ejemplo n.º 10
0
 public virtual void OnTouchEnd(TouchEventArgs ev)
 {
     TouchEnd?.Invoke(this, ev);
 }
Ejemplo n.º 11
0
 internal void OnTouchEnd(Model model, TouchEventArgs e) => TouchEnd?.Invoke(model, e);
 public virtual void OnTouchEnd()
 {
     TouchEnd?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 13
0
 public void UnRegistTouchEnd(TouchEnd end)
 {
     touchEnd -= end;
 }
Ejemplo n.º 14
0
 public void RegistTouchEnd(TouchEnd end)
 {
     touchEnd += end;
 }
Ejemplo n.º 15
0
 private void OnTouchEnd(Vector2 position)
 {
     TouchEnd?.Invoke(position);
 }