コード例 #1
0
    public int[] Tap()
    {
        int[] output = { 8, 8 };
        int   length = Input.touches.Length;

        if (length > 0)
        {
            foreach (Touch touch in Input.touches)
            {
                if (touch.position.x < Screen.width / 2)
                {
                    if (left == null)
                    {
                        left = new SwipeProfile();
                    }

                    int swipeCheck = SwipeCheck(touch, left);
                    if (swipeCheck != 8)
                    {
                        output[0] = swipeCheck;
                        if (output[0] != 0)
                        {
                            //Debug.Log("Debug Log: Output 0," + output[0]);
                        }
                    }
                }

                if (touch.position.x > Screen.width / 2)
                {
                    if (right == null)
                    {
                        right = new SwipeProfile();
                    }

                    int swipeCheck = SwipeCheck(touch, right);
                    if (swipeCheck != 8)
                    {
                        output[1] = swipeCheck;
                        if (output[1] != 0)
                        {
                            //Debug.Log("Debug Log: Output 1," + output[1]);
                        }
                    }
                }
            }
        }

        return(output);
    }
コード例 #2
0
    public int SwipeCheck(Touch touch, SwipeProfile swipeProfile)
    {
        if (touch.phase == TouchPhase.Began)
        {
            swipeProfile.beginSwipeFrame     = Time.frameCount;
            swipeProfile.swipeRegistered     = false;
            swipeProfile.holdRegistered      = false;
            swipeProfile.originTouchPosition = touch.position;
        }

        float distanceBetweenTouchesPrevious = Vector2.Distance(swipeProfile.originTouchPosition, touch.position);

        if (distanceBetweenTouchesPrevious > lengthRequiredRegisterSwipe && !swipeProfile.swipeRegistered)
        {
            swipeProfile.holdRegistered = false;
            swipeProfile.angle          = SwipeDirection(swipeProfile.originTouchPosition, touch.position);
            swipeProfile.direction      = AngleDirectionInt(swipeProfile.angle);

            swipeProfile.swipeRegistered = true;
            return(swipeProfile.direction);
        }

        /*
         * if the distance is less than the circle around the original contact and the number of frames has passed
         */
        int deltaFrame = Time.frameCount - swipeProfile.beginSwipeFrame;

        if (distanceBetweenTouchesPrevious < lengthRequiredRegisterHold && deltaFrame > framesRequiredHold || swipeProfile.holdRegistered)
        {
            swipeProfile.originTouchPosition = touch.position;
            swipeProfile.holdRegistered      = true;
            return(0);
        }

        if (touch.phase == TouchPhase.Ended)
        {
            swipeProfile.holdRegistered  = false;
            swipeProfile.swipeRegistered = false;
            return(8);
        }

        else
        {
            return(8);
        }
    }