Example #1
0
    /// <summary>
    /// Item들을 수평으로 정렬합니다. index 번 Item이 보이도록 정렬합니다.
    /// </summary>
    /// /// <param name="index"></param>
    public void SortItemToHorizontal(int index)
    {
        if (scrollView == null)
        {
            return;
        }
        RectTransform content = scrollView.content;

        float contentWidth       = 0;
        float viewPortXValue     = scrollView.viewport.rect.width * .5f;
        float targetContentWidth = 0;

        for (int i = 0; i < content.childCount; ++i)
        {
            WPScrollViewItem item = content.GetChild(i).GetComponent <WPScrollViewItem>();
            if (item == null)
            {
                continue;
            }
            item.SetPosition(new Vector2(contentWidth, 0));
            contentWidth += item.GetWidth();
            if (i == index)
            {
                targetContentWidth = contentWidth - (item.GetWidth() * .5f);
            }
        }
        content.sizeDelta = new Vector2(contentWidth, content.sizeDelta.y);
        WPGameCommon._WPDebug(viewPortXValue);
        content.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, viewPortXValue - targetContentWidth, content.rect.width);
        Canvas.ForceUpdateCanvases();
        scrollView.StopMovement();
    }
Example #2
0
    /// <summary>
    /// Item들을 아이템에 맞게 정렬합니다. 우선, 아이템을 수평으로 쌓아갑니다. 아이템이 수평으로 꽉 차면, 이제 그 아래로 아이템을 내려 또다시 수평으로 정렬합니다.
    /// </summary>
    public void SortItemToItem()
    {
        if (scrollView == null)
        {
            return;
        }
        RectTransform content       = scrollView.content;
        float         contentWidth  = 0;
        float         contentHeight = 0;
        float         nowWidth      = 0;
        float         nowHeight     = 0;
        Vector2       sizeDelta     = new Vector2(scrollView.viewport.rect.width, scrollView.viewport.rect.height);

        for (int i = 0; i < content.childCount; ++i)
        {
            WPScrollViewItem item = content.GetChild(i).GetComponent <WPScrollViewItem>();
            if (item == null)
            {
                continue;
            }
            if (nowWidth + item.GetWidth() > sizeDelta.x)
            {
                if (contentWidth < nowWidth)
                {
                    contentWidth = nowWidth;
                }
                contentHeight += nowHeight;
                nowWidth       = 0;
                nowHeight      = 0;
            }
            item.SetPosition(new Vector2(nowWidth, contentHeight));
            nowWidth += item.GetWidth();
            if (nowHeight < item.GetHeight())
            {
                nowHeight = item.GetHeight();
            }
        }
        content.sizeDelta = new Vector2(contentWidth, contentHeight);
        content.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, content.rect.width);
        content.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, content.rect.height);
        scrollView.StopMovement();
    }
Example #3
0
    /// <summary>
    /// Item들을 수평으로 정렬합니다.
    /// </summary>
    public void SortItemToHorizontal()
    {
        if (scrollView == null)
        {
            return;
        }
        RectTransform content = scrollView.content;

        float contentWidth = 0;

        for (int i = 0; i < content.childCount; ++i)
        {
            WPScrollViewItem item = content.GetChild(i).GetComponent <WPScrollViewItem>();
            if (item == null)
            {
                continue;
            }
            item.SetPosition(new Vector2(contentWidth, 0));
            contentWidth += item.GetWidth();
        }
        content.sizeDelta = new Vector2(contentWidth, content.sizeDelta.y);
        content.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, content.rect.width);
        scrollView.StopMovement();
    }