Пример #1
0
        public virtual void RefreshData(ContentPositionSetting contentPositionSetting = ContentPositionSetting.keep, Action onComplete = null)
        {
            Adapter.Initialize();

            PrepareRefreshAllBuffers();
            CalculateCellPosAndContentSize(contentPositionSetting);
            FillData();

            if (onComplete != null)
            {
                onComplete();
            }
        }
Пример #2
0
        private float CalculateCellPosAndContentSize(ContentPositionSetting contentPositionSetting = ContentPositionSetting.none)
        {
            float length  = 0;
            float offsetX = 0;
            float offsetY = 0;

            if (this.Vertical)
            {
                offsetY = 0;
                for (int i = 0; i < this.CellsCount;)
                {
                    //row head size
                    Vector2 rowHeadSize    = GetElementSize(i);
                    float   cellWidth      = rowHeadSize.x;
                    float   maxHeightInRow = rowHeadSize.y;
                    float   currentHeight  = rowHeadSize.y;

                    offsetX = 0;

                    int j = 0;
                    for (j = 0; Mathf.Abs(offsetX) + cellWidth <= this.viewportSize.x && i + j < this.CellsCount; j++)
                    {
                        int     elementIndex = i + j;
                        Vector3 localPos     = new Vector3(offsetX, -offsetY, 0.0f);
                        this.AddElementPositionInfo(elementIndex, localPos);
                        if (this.Left2Right)
                        {
                            offsetX += cellWidth + Spacing.x;
                        }
                        else
                        {
                            offsetX -= cellWidth + Spacing.x;
                        }
                        if (currentHeight > maxHeightInRow)
                        {
                            maxHeightInRow = currentHeight;
                        }

                        Vector2 nextElementSize = GetElementSize(elementIndex + 1);
                        cellWidth     = nextElementSize.x;
                        currentHeight = nextElementSize.y;
                    }
                    offsetY += maxHeightInRow + Spacing.y;
                    i       += j;
                }

                length = offsetY;
                if (length < ScrollRectTransform.rect.size.y)
                {
                    length = ScrollRectTransform.rect.size.y;
                }

                content.sizeDelta = new Vector2(this.viewportSize.x, length);

                if (contentPositionSetting == ContentPositionSetting.gotoBegin)
                {
                    content.localPosition = Vector3.zero;
                }
            }
            else if (this.Horizontal)
            {
                offsetX = 0;
                for (int i = 0; i < this.CellsCount;)
                {
                    //colunm head size
                    Vector2 columnHeadSize   = GetElementSize(i);
                    float   cellHeight       = columnHeadSize.y;
                    float   maxWidthInColunm = columnHeadSize.x;
                    float   currentWidth     = columnHeadSize.x;

                    offsetY = 0;
                    int j = 0;
                    for (j = 0; Mathf.Abs(offsetY) + cellHeight <= this.viewportSize.y && i + j < this.CellsCount; j++)
                    {
                        int     elementIndex = i + j;
                        Vector3 localPos     = new Vector3(offsetX, offsetY, 0.0f);
                        this.AddElementPositionInfo(elementIndex, localPos);
                        offsetY -= cellHeight + Spacing.y;
                        if (currentWidth > maxWidthInColunm)
                        {
                            maxWidthInColunm = currentWidth;
                        }

                        Vector2 nextElementSize = GetElementSize(elementIndex + 1);
                        cellHeight   = nextElementSize.y;
                        currentWidth = nextElementSize.x;
                    }
                    if (this.Left2Right)
                    {
                        offsetX += maxWidthInColunm + Spacing.x;
                    }
                    else
                    {
                        offsetX -= maxWidthInColunm + Spacing.x;
                    }
                    i += j;
                }

                length = Mathf.Abs(offsetX);
                if (length < ScrollRectTransform.rect.size.x)
                {
                    length = ScrollRectTransform.rect.size.x;
                }

                content.sizeDelta = new Vector2(length, this.viewportSize.y);

                if (contentPositionSetting == ContentPositionSetting.gotoBegin)
                {
                    content.localPosition = Vector3.zero;
                }
            }

            return(length);
        }