Example #1
0
        public void DragLeftPageToPoint(Vector3 point)
        {
            if (currentPaper <= StartFlippingPaper)
            {
                return;
            }
            pageDragging = true;
            mode         = FlipMode.LeftToRight;
            f            = point;

            UpdatePages();

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

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

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


            if (enableShadowEffect)
            {
                shadowLTR.gameObject.SetActive(true);
            }
            clipImage.gameObject.SetActive(true);
            UpdateBookLTRToPoint(f);
        }
Example #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.Count; i++)
            {
                BookUtility.HidePage(papers[i].Front);
                papers[i].Front.transform.SetParent(target.transform);
                BookUtility.HidePage(papers[i].Back);
                papers[i].Back.transform.SetParent(target.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(target.transform);
                    papers[i].Back.transform.SetSiblingIndex(i);
                    BookUtility.CopyTransform(LeftPage.transform, papers[i].Back.transform);
                }

                //Show the front page of all next papers
                for (int i = papers.Count - 1; i >= currentPaper; i--)
                {
                    BookUtility.ShowPage(papers[i].Front);
                    papers[i].Front.transform.SetSiblingIndex(papers.Count - i + previousPaper);
                    BookUtility.CopyTransform(RightPage.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(LeftPage.transform, papers[previousPaper].Back.transform);
                }
                //show front of current page only
                if (currentPaper <= papers.Count - 1)
                {
                    BookUtility.ShowPage(papers[currentPaper].Front);
                    papers[currentPaper].Front.transform.SetSiblingIndex(papers.Count - currentPaper + previousPaper);
                    BookUtility.CopyTransform(RightPage.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
                    shadowLImage.gameObject.SetActive(true);
                    shadowLImage.transform.SetParent(papers[previousPaper].Back.transform, true);
                    shadowLImage.rectTransform.anchoredPosition = new Vector3();
                    shadowLImage.rectTransform.localRotation    = Quaternion.identity;
                }
                else
                {
                    //if no previous pages, the leftShaow should be disabled
                    shadowLImage.gameObject.SetActive(false);
                    shadowLImage.transform.SetParent(target, true);
                }

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

                shadowRImage.gameObject.SetActive(false);
                shadowRImage.transform.SetParent(target, true);
            }
            #endregion
        }