Exemple #1
0
    private void MonitorSwiping()
    {
        //check for screen swiping and update camera accordingly
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            Vector3 target = transform.localRotation.eulerAngles;
            switch (touch.phase)
            {
            case TouchPhase.Began:
                startPos  = touch.position;
                lastPos   = touch.position;
                startTime = Time.time;
                break;

            case TouchPhase.Moved:
                //detect whether the finger initially moves far enough to count as a swipe movement
                if (!isAVerticalSwipe && shouldMonitorHorizontalSwiping && Mathf.Abs(touch.position.x - startPos.x) > swipeThreshold)
                {
                    isAHorizontalSwipe = true;
                }

                if (!isAHorizontalSwipe && shouldMonitorVerticalSwiping && Mathf.Abs(touch.position.y - startPos.y) > swipeThreshold)
                {
                    isAVerticalSwipe = true;
                }

                if (isAHorizontalSwipe)
                {
                    float changeInX = touch.position.x - lastPos.x;
                    target.y -= ((changeInX / Screen.width) * 54);
                    DOTween.CompleteAll();
                    transform.DOLocalRotate(target, Time.deltaTime).Play();
                }

                if (isAVerticalSwipe)
                {
                    float changeInY = touch.position.y - lastPos.y;
                    target.x += ((changeInY / Screen.height) * 36);
                    DOTween.CompleteAll();
                    transform.DOLocalRotate(target, Time.deltaTime).Play();
                }

                lastPos = touch.position;
                break;

            case TouchPhase.Ended:
                if (isAHorizontalSwipe)
                {
                    swipeSpeed = (((startPos.x - touch.position.x) / Screen.width) * 36) / (Time.time - startTime);
                    swipeSpeed = swipeSpeed > 0 ? Mathf.Max(swipeSpeed, 30) : Mathf.Min(swipeSpeed, -30);

                    target.y += (swipeSpeed * 0.3f);

                    screenManager.SetClosestScreenAsFocused(Quaternion.Euler(target));
                    FocusCameraOnCurrentScreen();
                    isAHorizontalSwipe = false;
                }

                if (isAVerticalSwipe)
                {
                    swipeSpeed = (((startPos.y - touch.position.y) / Screen.height) * 36) / (Time.time - startTime);
                    swipeSpeed = swipeSpeed > 0 ? Mathf.Max(swipeSpeed, 30) : Mathf.Min(swipeSpeed, -30);

                    target.x -= (swipeSpeed * 0.3f);

                    screenManager.MoveBetweenVerticalLayers(Quaternion.Euler(target));
                    isAVerticalSwipe = false;
                }
                break;
            }
        }
        //check camera position and update infoScreens accordingly
        if (isAHorizontalSwipe)
        {
            screenManager.SetClosestScreenAsFocused(transform.localRotation);
        }
    }