Example #1
0
    // Animation during turning to next page
    IEnumerator TurnToNextPageTransition()
    {
        bool hasActivatedNextPage = false;

        // Play flip page sound
        PlayFlipPageSound();

        if (inTransition == PAGES_TRANSITIONS.TURNING_LEFT)
        {
            t = 1 - t;
        }

        inTransition = PAGES_TRANSITIONS.TURNING_RIGHT;
        while (t < 1)
        {
            bookPages[currentPage % 3].page.localRotation =
                Quaternion.Lerp(pageUnturnedRotation, pageTurnedRotation, t);
            t += Time.deltaTime * speed;

            if (t > 0.05f && !hasActivatedNextPage)
            {
                // Activate the next page just after animation has started to prevent visual overlap
                if (currentPage + 1 < pagesUi.Count)
                {
                    ActivatePage((currentPage + 1) % 3, currentPage + 1);
                    bookPages[(currentPage + 1) % 3].page.localRotation = pageUnturnedRotation;
                }

                hasActivatedNextPage = true;
            }

            yield return(new WaitForFixedUpdate());
        }

        bookPages[currentPage % 3].page.localRotation = pageTurnedRotation;

        // Deactivate the previous page
        DeactivatePage((currentPage + 2) % 3);

        currentPage++;
        if (currentPage > pagesUi.Count)
        {
            currentPage = pagesUi.Count;
        }

        TransitionFinished();
    }
Example #2
0
 // When transition is finished, reset variables used during transition
 private void TransitionFinished()
 {
     t            = 0;
     inTransition = PAGES_TRANSITIONS.NONE;
     speed        = 2.5f;
 }