Exemplo n.º 1
0
        void Update()
        {
            SetEdge();
            if (mLoop && pageSize > 0 && pageController.pageCount >= 2)
            {
                UIPageController  pageCtrl = target.gameObject.GetComponent <UIPageController>();
                List <GameObject> pages    = pageCtrl.GetAllPages();
                float             pageY    = pages[0].transform.localPosition.y;
                float             pageZ    = pages[0].transform.localPosition.z;

                pages[0].transform.localPosition = new Vector3(0, pageY, pageZ);
                pages[pageController.pageCount - 1].transform.localPosition = new Vector3(pageSize * (pageController.pageCount - 1), pageY, pageZ);

                Vector3 localPostion = target.transform.localPosition;

                if ((localPostion.x < pageSize) && (localPostion.x > 0))
                {
                    pages[pageController.pageCount - 1].transform.localPosition = new Vector3(-pageSize, pageY, pageZ);
                }


                float fPageToalSize = -pageSize * (pageController.pageCount - 1);

                if (localPostion.x <= fPageToalSize)
                {
                    pages[0].transform.localPosition = new Vector3(pageSize * pageController.pageCount, pageY, pageZ);
                }
            }
        }
Exemplo n.º 2
0
 void Start()
 {
     pageController = NGUITools.FindInParents <UIPageController>(gameObject);
 }
Exemplo n.º 3
0
        void OnPress(bool pressed)
        {
            UIPageController  PageControl = target.gameObject.GetComponent <UIPageController>();
            List <GameObject> pages       = PageControl.GetAllPages();
            float             pageY       = pages[0].transform.localPosition.y;
            float             pageZ       = pages[0].transform.localPosition.z;

            if (mLoop)
            {
                pages[0].transform.localPosition  = new Vector3(0, pageY, pageZ);
                pages[11].transform.localPosition = new Vector3(pageSize * (pageController.pageCount - 1), pageY, pageZ);
            }

            if (enabled && gameObject.active && target != null && pageSize > 0 && pageController.pageCount >= 1)
            {
                if (pressed)
                {
                    sendOpenAllPage();
                    stopTarget();
                    // Remember the hit position
                    mLastPos          = UICamera.lastHit.point;
                    pressLastTime     = Time.timeSinceLevelLoad;
                    lastLocalPostionX = target.transform.localPosition.x;
                    // Create the plane to drag along
                    Transform trans = UICamera.currentCamera.transform;
                    mPlane = new Plane(trans.rotation * Vector3.back, mLastPos);
                }
                else
                {
                    Vector3 localPostion = target.transform.localPosition;
                    int     dstPage      = 0;
                    if (localPostion.x <= leftEdge)
                    {
                        //Turn right
                        localPostion.x = leftEdge;
                        dstPage        = pageController.pageCount - 1;

                        if (mLoop)
                        {
                            float xTransSincePress = target.transform.localPosition.x - lastLocalPostionX;
                            float timeSincePress   = Time.timeSinceLevelLoad - pressLastTime;
                            float xSpeed           = xTransSincePress / timeSincePress;

                            if (Mathf.Abs(xSpeed) > 200)
                            {
                                float offX = target.transform.localPosition.x + pageSize * (pageController.pageCount - 1);
                                dstPage        = 0;
                                localPostion.x = getDestX(dstPage);

                                float y = target.transform.localPosition.y;
                                float z = target.transform.localPosition.z;
                                target.transform.localPosition = new Vector3(localPostion.x + pageSize + offX, y, z);

                                pages[pageController.pageCount - 1].transform.localPosition = new Vector3(-pageSize, pageY, pageZ);
                            }
                        }
                    }
                    else if (localPostion.x >= rightEdge)
                    {
                        //Turn Left
                        localPostion.x = rightEdge;
                        dstPage        = 0;

                        if (mLoop)
                        {
                            float xTransSincePress = target.transform.localPosition.x - lastLocalPostionX;
                            float timeSincePress   = Time.timeSinceLevelLoad - pressLastTime;
                            float xSpeed           = xTransSincePress / timeSincePress;

                            if (Mathf.Abs(xSpeed) > 200)
                            {
                                float offX = target.transform.localPosition.x;
                                dstPage        = GetPageCount() - 1;
                                localPostion.x = getDestX(dstPage);

                                float y = target.transform.localPosition.y;
                                float z = target.transform.localPosition.z;
                                target.transform.localPosition = new Vector3(localPostion.x - pageSize + offX, y, z);

                                pages[0].transform.localPosition = new Vector3(pageSize * pageController.pageCount, pageY, pageZ);
                            }
                        }
                    }
                    else
                    {
                        float xTransSincePress = localPostion.x - lastLocalPostionX;
                        float timeSincePress   = Time.timeSinceLevelLoad - pressLastTime;
                        float xSpeed           = xTransSincePress / timeSincePress;

                        float transX = (localPostion.x - startPageX) / pageSize;
                        if (Mathf.Abs(xSpeed) > 200)
                        {
                            if (xSpeed > 0)
                            {
                                transX = Mathf.Ceil(transX);
                            }
                            else
                            {
                                transX = Mathf.Floor(transX);
                            }
                        }
                        int turnPage = Mathf.RoundToInt(transX);
                        dstPage        = -turnPage;
                        localPostion.x = getDestX(dstPage);
                    }
                    sendPage(dstPage);
                    moveTarget(localPostion);
                }
            }
        }