示例#1
0
    private void CheckStandaloneInput()
    {
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            OnInputHandledEvent?.Invoke(BoardInputs.LEFT);
        }

        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            OnInputHandledEvent?.Invoke(BoardInputs.RIGHT);
        }

        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            OnInputHandledEvent?.Invoke(BoardInputs.ROTATE);
        }

        if (Input.GetKey(KeyCode.DownArrow))
        {
            OnInputHandledEvent?.Invoke(BoardInputs.DOWN);
        }

        if (Input.GetKeyUp(KeyCode.DownArrow))
        {
            OnInputHandledEvent?.Invoke(BoardInputs.REFRESH);
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            OnInputHandledEvent?.Invoke(BoardInputs.FORCE_DOWN);
        }
    }
示例#2
0
    private void CheckTVOSInput()
    {
        // area click
        if (Input.GetKeyDown(KeyCode.JoystickButton14))
        {
            shouldSwipe = false;
            OnInputHandledEvent?.Invoke(BoardInputs.ROTATE);
            return;
        }


        if (Input.touchCount == 0)
        {
            return;
        }

        Touch touch = Input.GetTouch(0);

        switch (touch.phase)
        {
        case TouchPhase.Began:
            touchPosition  = touch.position;
            shouldSwipe    = true;
            moveDown       = false;
            startSwipeTime = Time.time;
            break;

        case TouchPhase.Moved:
            if (!shouldSwipe)
            {
                return;
            }

            currentPosition = touch.position;
            moveDown        = false;
            float swipeDistance = (currentPosition - touchPosition).sqrMagnitude;

            if (swipeDistance > minSwipeDistance * minSwipeDistance)
            {
                var swipeDirection = SwipeDirection(_from: touchPosition, _to: currentPosition);
                switch (swipeDirection)
                {
                case SwipeDirections.SWIPE_DOWN:
                    OnInputHandledEvent?.Invoke(BoardInputs.DOWN);
                    moveDown = true;
                    break;
                }
            }
            break;

        case TouchPhase.Stationary:
            if (!shouldSwipe)
            {
                return;
            }
            if (moveDown)
            {
                OnInputHandledEvent?.Invoke(BoardInputs.DOWN);
            }

            break;

        case TouchPhase.Canceled:
            if (!shouldSwipe)
            {
                return;
            }
            OnInputHandledEvent?.Invoke(BoardInputs.REFRESH);
            break;

        case TouchPhase.Ended:
            if (!shouldSwipe)
            {
                return;
            }

            OnInputHandledEvent?.Invoke(BoardInputs.REFRESH);
            swipeDistance = (currentPosition - touchPosition).magnitude;
            float finishSwipeTime = Time.time - startSwipeTime;
            float swipeForce      = swipeDistance / finishSwipeTime;
            if (swipeDistance > minSwipeDistance)
            {
                switch (SwipeDirection(_from: touchPosition, _to: currentPosition))
                {
                case SwipeDirections.SWIPE_LEFT:
                    OnInputHandledEvent?.Invoke(BoardInputs.LEFT);
                    break;

                case SwipeDirections.SWIPE_RIGHT:
                    OnInputHandledEvent?.Invoke(BoardInputs.RIGHT);
                    break;

                case SwipeDirections.SWIPE_UP:
                    OnInputHandledEvent?.Invoke(BoardInputs.ROTATE);
                    break;

                case SwipeDirections.SWIPE_DOWN:
                    if (swipeForce > swipeForceBorderValue * swipeForceBorderValue && moveDown)
                    {
                        OnInputHandledEvent?.Invoke(BoardInputs.FORCE_DOWN);
                        shouldSwipe = false;
                        moveDown    = false;
                    }
                    break;
                }
            }
            break;
        }
    }