Ejemplo n.º 1
0
    public void AutoDragLeftPageToPoint(Vector3 point)
    {
        if (targetPageNumber <= StartFlippingPaper)
        {
            return;
        }
        pageDragging = true;
        mode         = FlipMode.LeftToRight;
        f            = point;

        UpdatePages();

        ClippingPlane.rectTransform.pivot = new Vector2(0, 0.35f);

        BookUtility.HidePage(papers[currentPaper - 2].Back);
        BookUtility.ShowPage(papers[targetPageNumber - 1].Back);

        Right = papers[currentPaper - 1].Back.GetComponent <Image>();
        BookUtility.ShowPage(Right.gameObject);
        Right.transform.position         = LeftPageTransform.transform.position;
        Right.transform.localEulerAngles = new Vector3(0, 0, 0);
        Right.transform.SetAsFirstSibling();

        Left = papers[targetPageNumber].Front.GetComponent <Image>();
        BookUtility.ShowPage(Left.gameObject);
        Left.gameObject.SetActive(true);
        Left.rectTransform.pivot        = new Vector2(1, 0);
        Left.transform.position         = LeftPageTransform.transform.position;
        Left.transform.localEulerAngles = new Vector3(0, 0, 0);

        if (enableShadowEffect)
        {
            ShadowLTR.gameObject.SetActive(true);
        }
        ClippingPlane.gameObject.SetActive(true);
        UpdateBookLTRToPoint(f);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Update page orders
    /// This function should be called whenever the current page changed, the dragging of the page started or the page has been flipped
    /// </summary>
    public void UpdatePages()
    {
        int previousPaper = pageDragging ? currentPaper - 2 : currentPaper - 1;

        //Hide all pages
        for (int i = 0; i < papers.Length; i++)
        {
            BookUtility.HidePage(papers[i].Front);
            papers[i].Front.transform.SetParent(BookPanel.transform);
            BookUtility.HidePage(papers[i].Back);
            papers[i].Back.transform.SetParent(BookPanel.transform);
        }

        if (hasTransparentPages)
        {
            //Show the back page of all previous papers
            for (int i = 0; i <= previousPaper; i++)
            {
                BookUtility.ShowPage(papers[i].Back);
                papers[i].Back.transform.SetParent(BookPanel.transform);
                papers[i].Back.transform.SetSiblingIndex(i);
                BookUtility.CopyTransform(LeftPageTransform.transform, papers[i].Back.transform);
            }

            //Show the front page of all next papers
            for (int i = papers.Length - 1; i >= currentPaper; i--)
            {
                BookUtility.ShowPage(papers[i].Front);
                papers[i].Front.transform.SetSiblingIndex(papers.Length - i + previousPaper);
                BookUtility.CopyTransform(RightPageTransform.transform, papers[i].Front.transform);
            }
        }
        else
        {
            //show back of previous page only
            if (previousPaper >= 0)
            {
                BookUtility.ShowPage(papers[previousPaper].Back);
                //papers[previousPaper].Back.transform.SetParent(BookPanel.transform);
                //papers[previousPaper].Back.transform.SetSiblingIndex(previousPaper);
                BookUtility.CopyTransform(LeftPageTransform.transform, papers[previousPaper].Back.transform);
            }
            //show front of current page only
            if (currentPaper <= papers.Length - 1)
            {
                BookUtility.ShowPage(papers[currentPaper].Front);
                papers[currentPaper].Front.transform.SetSiblingIndex(papers.Length - currentPaper + previousPaper);
                BookUtility.CopyTransform(RightPageTransform.transform, papers[currentPaper].Front.transform);
            }
        }
        #region Shadow Effect
        if (enableShadowEffect)
        {
            //the shadow effect enabled
            if (previousPaper >= 0)
            {
                //has at least one previous page, then left shadow should be active
                LeftPageShadow.gameObject.SetActive(true);
                LeftPageShadow.transform.SetParent(papers[previousPaper].Back.transform, true);
                LeftPageShadow.rectTransform.anchoredPosition = new Vector3();
                LeftPageShadow.rectTransform.localRotation    = Quaternion.identity;
            }
            else
            {
                //if no previous pages, the leftShaow should be disabled
                LeftPageShadow.gameObject.SetActive(false);
                LeftPageShadow.transform.SetParent(BookPanel, true);
            }

            if (currentPaper < papers.Length)
            {
                //has at least one next page, the right shadow should be active
                RightPageShadow.gameObject.SetActive(true);
                RightPageShadow.transform.SetParent(papers[currentPaper].Front.transform, true);
                RightPageShadow.rectTransform.anchoredPosition = new Vector3();
                RightPageShadow.rectTransform.localRotation    = Quaternion.identity;
            }
            else
            {
                //no next page, the right shadow should be diabled
                RightPageShadow.gameObject.SetActive(false);
                RightPageShadow.transform.SetParent(BookPanel, true);
            }
        }
        else
        {
            //Enable Shadow Effect is Unchecked, all shadow effects should be disabled
            LeftPageShadow.gameObject.SetActive(false);
            LeftPageShadow.transform.SetParent(BookPanel, true);

            RightPageShadow.gameObject.SetActive(false);
            RightPageShadow.transform.SetParent(BookPanel, true);
        }
        #endregion
    }