示例#1
0
 private static void LastFix2_Left(UIPageController pageControl, float turnButtonSpace)
 {
     for (int i = 0; i < pageControl.pageBtns.Length; i++)
     {
         pageControl.pageBtns [i].transform.localPosition = new Vector3(turnButtonSpace * i, 0.0f, 0.0f);
     }
 }
示例#2
0
    void Update()
    {
        if (mLoop && pageSize > 0 && pageCount >= 2)
        {
            UIPageController PageControl = target.gameObject.GetComponent <UIPageController>();
            GameObject[]     pages       = PageControl.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[pageCount - 1].transform.localPosition = new Vector3(pageSize * (pageCount - 1), pageY, pageZ);

            Vector3 localPostion = target.transform.localPosition;

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


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

            if (localPostion.x <= fPageToalSize)
            {
                pages[0].transform.localPosition = new Vector3(pageSize * pageCount, pageY, pageZ);
            }
        }
    }
示例#3
0
 private static void LastFix1(UIPageController pageControl, int pageSize)
 {
     UIDragXPage[] childDrags = pageControl.gameObject.GetComponentsInChildren <UIDragXPage> ();
     foreach (UIDragXPage childDrag in childDrags)
     {
         childDrag.SetPageInformation(pageControl.transform, pageSize, pageControl.pages.Length);
     }
 }
示例#4
0
    public static GameObject AddOnePage(UIPageController pageControl, GameObject pagePrefeb, int pageSize)
    {
        pageControl.OpenAllPage();
        GameObject page = AddPageStep1(pageControl, pagePrefeb, pageSize);

        LastFix1(pageControl, pageSize);
        pageControl.LeavePage();
        return(page);
    }
示例#5
0
 public static void AddOnePage2(UIPageController pageControl, GameObject pagePrefeb, GameObject turnPrefeb, Transform turnRoot, int pageSize, float turnButtonSpace, out GameObject madepage, out GameObject madeTurn)
 {
     pageControl.OpenAllPage();
     madepage = AddPageStep1(pageControl, pagePrefeb, pageSize);
     madeTurn = AddPageStep2_Optional(pageControl, turnRoot, turnPrefeb);
     LastFix1(pageControl, pageSize);
     LastFix2_Left(pageControl, turnButtonSpace);
     pageControl.LeavePage();
 }
示例#6
0
    private static void LastFix2(UIPageController pageControl, float turnButtonSpace)
    {
        float startX = -(pageControl.pageBtns.Length - 1) / 2.0f * turnButtonSpace;

        foreach (GameObject turn in pageControl.pageBtns)
        {
            turn.transform.localPosition = new Vector3(startX, 0.0f, 0.0f);
            startX += turnButtonSpace;
        }
    }
示例#7
0
    public static GameObject AddOnePage(UIPageController pageControl, GameObject pagePrefeb, GameObject turnPrefeb, Transform turnRoot, int pageSize, float turnButtonSpace)
    {
        pageControl.OpenAllPage();
        GameObject page = AddPageStep1(pageControl, pagePrefeb, pageSize);

        AddPageStep2_Optional(pageControl, turnRoot, turnPrefeb);
        LastFix1(pageControl, pageSize);
        LastFix2(pageControl, turnButtonSpace);
        pageControl.LeavePage();
        return(page);
    }
示例#8
0
    /// <summary>
    /// 添加一个翻页的显示按钮,本步骤为可选的
    /// </summary>
    private static GameObject AddPageStep2_Optional(UIPageController pageControl, Transform turnRoot, GameObject turnButtonPrefeb)
    {
        GameObject turnButton = (GameObject)GameObject.Instantiate(turnButtonPrefeb);

        turnButton.transform.parent = turnRoot;
        Vector3 scale = turnButton.transform.localScale;

        scale.Set(1.0f, 1.0f, 1.0f);
        turnButton.transform.localScale = scale;
        UITurnButtonController turnContoller = turnButton.GetComponent <UITurnButtonController> ();

        turnContoller.pageBtnID = pageControl.pageBtns != null ? pageControl.pageBtns.Length : 0;
        turnContoller.ctrl      = pageControl;
        pageControl.pageBtns    = addGameObject(pageControl.pageBtns, turnButton);
        turnButton.SendMessage("OnReset", SendMessageOptions.DontRequireReceiver);
        return(turnButton);
    }
示例#9
0
    /// <summary>
    /// 首先添加一个页的prefeb到某个页根节点下
    /// </summary>
    private static GameObject AddPageStep1(UIPageController pageControl, GameObject pagePrefeb, int pageSize)
    {
        int        currentPageSize = pageControl.pages != null ? pageControl.pages.Length : 0;
        GameObject page            = (GameObject)GameObject.Instantiate(pagePrefeb);

        page.transform.parent = pageControl.gameObject.transform;
        Vector3 scale = page.transform.localScale;

        scale.Set(1.0f, 1.0f, 1.0f);
        page.transform.localScale    = scale;
        page.transform.localPosition = new Vector3(pageSize * currentPageSize, 0.0f, 0.0f);
        pageControl.pages            = addGameObject(pageControl.pages, page);
        if (pageControl.pageCell0 == null)
        {
            pageControl.pageCell0 = page;
        }
        return(page);
    }
示例#10
0
    protected virtual void OnPress(bool pressed)
    {
        UIPageController PageControl = target.gameObject.GetComponent <UIPageController>();

        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 * (pageCount - 1), pageY, pageZ);
        }

        if (enabled && gameObject.activeSelf && target != null && pageSize > 0 && pageCount >= 2)
        {
            if (pressed)
            {
                //sendOpenAllPage ();
                stopTarget();
                // Remember the hit position
                mLastPos          = UICamera.lastHit.point;
                pressLastTime     = Time.timeSinceLevelLoad;
                lastLocalPostionX = target.transform.localPosition.x;
                if (pageCount > 4)
                {
                    int currentPage = (int)Mathf.Abs(lastLocalPostionX - startPageX) / pageSize;
                    target.SendMessage("OpenNextPage", currentPage, SendMessageOptions.DontRequireReceiver);
                }
                else
                {
                    sendOpenAllPage();
                }
                // Create the plane to drag along
                Transform trans = UICamera.lastCamera.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        = 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 * (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[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 * 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);
                        }
                        target.SendMessage("OpenNextPage", -Mathf.RoundToInt(transX), SendMessageOptions.DontRequireReceiver);
                    }
                    int turnPage = Mathf.RoundToInt(transX);
                    dstPage        = -turnPage;
                    localPostion.x = getDestX(dstPage);
                }
                sendPage(dstPage);
                moveTarget(localPostion);
            }
        }
    }