Example #1
0
        private void CreateCell(int index)
        {
            BaseCell <T> cell = Instantiate(cellObject).GetComponent <BaseCell <T> >();

            cell.SetAnchors(scrollRect.content.anchorMin, scrollRect.content.anchorMax);
            cell.transform.SetParent(scrollRect.content.transform, false);
            UpdateCell(cell, index);

            if (scrollDirection == Direction.Vertical)
            {
                if (scrollReverse)
                {
                    cell.Bottom = (cells.Count > 0 ? cells.Last.Value.Top + spacing : contentPadding.bottom);
                }
                else
                {
                    cell.Top = (cells.Count > 0 ? cells.Last.Value.Bottom - spacing : -contentPadding.top);
                }
                cell.SetOffsetHorizontal(contentPadding.left, contentPadding.right);
            }
            else if (scrollDirection == Direction.Horizontal)
            {
                if (scrollReverse)
                {
                    cell.Right = (cells.Count > 0 ? cells.Last.Value.Left - spacing : -contentPadding.right);
                }
                else
                {
                    cell.Left = (cells.Count > 0 ? cells.Last.Value.Right + spacing : contentPadding.left);
                }
                cell.SetOffsetVertical(contentPadding.top, contentPadding.bottom);
            }

            cells.AddLast(cell);
        }
Example #2
0
        private void MoveCellLastToFirst()
        {
            if (cells.Count == 0)
            {
                return;
            }

            BaseCell <T> lastCell  = cells.Last.Value;
            BaseCell <T> firstCell = cells.First.Value;

            UpdateCell(lastCell, firstCell.dataIndex - 1);

            if (scrollDirection == Direction.Vertical)
            {
                if (scrollReverse)
                {
                    lastCell.Top = firstCell.Bottom - spacing;
                }
                else
                {
                    lastCell.Bottom = firstCell.Top + spacing;
                }
                lastCell.SetOffsetHorizontal(contentPadding.left, contentPadding.right);
            }
            else if (scrollDirection == Direction.Horizontal)
            {
                if (scrollReverse)
                {
                    lastCell.Left = firstCell.Right + spacing;
                }
                else
                {
                    lastCell.Right = firstCell.Left - spacing;
                }
                lastCell.SetOffsetVertical(contentPadding.top, contentPadding.bottom);
            }

            cells.RemoveLast();
            cells.AddFirst(lastCell);
        }