Ejemplo n.º 1
0
    void Update()
    {
        swipeDown = false;
        swipeUp   = false;
        zoomOut   = false;
        zoomIn    = false;

        // dont run Update() if there is no gesture listener
        if (!gestureListener)
        {
            return;
        }

        if (!isSpinning)
        {
            if (slideChangeWithKeys)
            {
                if (Input.GetKeyDown(KeyCode.PageDown) && timeRemaining > 0)
                {
                    //RotateLeft();
                    IncrementScore();
                    timerBool = true;
                }
                else if (Input.GetKeyDown(KeyCode.PageUp))
                {
                    timerBool         = false;
                    timeRemaining     = 60;
                    jumpCounter       = 0;
                    jumpJackText.text = jumpCounter.ToString();
                }
            }

            if (slideChangeWithGestures && gestureListener)
            {
                if (gestureListener.IsSwipeLeft())
                {
                    //RotateLeft();
                    NextScreen();
                }
                else if (gestureListener.IsSwipeRight())
                {
                    //RotateRight();
                    PreviousScreen();
                }
                if (gestureListener.IsSwipeDown())
                {
                    swipeDown = true;
                    Debug.Log("down");
                }

                if (gestureListener.IsSwipeUp())
                {
                    swipeUp = true;
                    Debug.Log("up");
                }

                if (gestureListener.IsZoomOut())
                {
                    zoomOut = true;
                    Debug.Log("zoomout");
                }

                if (gestureListener.IsZoomIn())
                {
                    zoomIn = true;
                    Debug.Log("zoomin");
                }


                //else if(gestureListener.IsSwipeUp())
                //RotateUp();
            }

            if (slideChangeWithGestures && gestureListener && timeRemaining > 0)
            {
                if (gestureListener.IsJump())
                {
                    IncrementScore();
                    timerBool = true;
                }
            }
        }
        else
        {
            // spin the presentation
            if (stepsToGo > 0)
            {
                //if(Time.realtimeSinceStartup >= nextStepTime)
                {
                    if (screenCamera)
                    {
                        transform.RotateAround(transform.position, screenCamera.transform.TransformDirection(rotationAxis), rotationStep);
                    }
                    else
                    {
                        transform.Rotate(rotationAxis * rotationStep, Space.World);
                    }

                    stepsToGo--;
                    //nextStepTime = Time.realtimeSinceStartup + Time.deltaTime;
                }
            }
            else
            {
                Quaternion cubeRotation = Quaternion.Euler(rotationAxis * rotationStep * 90f / spinSpeed) * initialRotation;
                transform.rotation = screenCamera ? screenCamera.transform.rotation * cubeRotation : cubeRotation;
                isSpinning         = false;
            }
        }

        //

        if (_lerp)
        {
            // prevent overshooting with values greater than 1
            float decelerate = Mathf.Min(decelerationRate * Time.deltaTime, 1f);
            _container.anchoredPosition = Vector2.Lerp(_container.anchoredPosition, _lerpTo, decelerate);
            // time to stop lerping?
            if (Vector2.SqrMagnitude(_container.anchoredPosition - _lerpTo) < 0.25f)
            {
                // snap to target and stop lerping
                _container.anchoredPosition = _lerpTo;
                _lerp = false;
                // clear also any scrollrect move that may interfere with our lerping
                _scrollRectComponent.velocity = Vector2.zero;
            }

            // switches selection icon exactly to correct page
            if (_showPageSelection)
            {
                SetPageSelection(GetNearestPage());
            }
        }

        TimeDisplay();
        Instructions();

        if (timerBool == true)
        {
            timeRemaining -= Time.deltaTime;
        }
    }