private void MoveCellLastToFirst() { if (itemsLinkedList.Count == 0) { return; } ReuseItem lastCell = itemsLinkedList.Last.Value; ReuseItem firstCell = itemsLinkedList.First.Value; UpdateItem(lastCell, firstCell.DataIndex - 1); if (ScrollDirection == Direction.Vertical) { lastCell.Bottom = firstCell.Top + Spacing; lastCell.SetOffsetHorizontal(0, 0); } else if (ScrollDirection == Direction.Horizontal) { lastCell.Right = firstCell.Left - Spacing; lastCell.SetOffsetVertical(0, 0); } itemsLinkedList.RemoveLast(); itemsLinkedList.AddFirst(lastCell); }
private void MoveCellFirstToLast() { if (itemsLinkedList.Count == 0) { return; } ReuseItem firstCell = itemsLinkedList.First.Value; ReuseItem lastCell = itemsLinkedList.Last.Value; UpdateItem(firstCell, lastCell.DataIndex + 1); if (ScrollDirection == Direction.Vertical) { firstCell.Top = lastCell.Bottom - Spacing; firstCell.SetOffsetHorizontal(0, 0); } else if (ScrollDirection == Direction.Horizontal) { firstCell.Left = lastCell.Right + Spacing; firstCell.SetOffsetVertical(0, 0); } itemsLinkedList.RemoveFirst(); itemsLinkedList.AddLast(firstCell); }
private void UpdateItem(ReuseItem cell, int index) { cell.DataIndex = index; if (cell.DataIndex >= 0 && cell.DataIndex < itemDataList.Count) { cell.UpdateSetDataToItem(itemDataList[cell.DataIndex]); cell.gameObject.SetActive(true); } else { cell.gameObject.SetActive(false); } }
private void CreateItem(int index) { ReuseItem reuseItem = Instantiate(itemObject).GetComponent <ReuseItem>(); reuseItem.SetAnchors(scrollRect.content.anchorMin, scrollRect.content.anchorMax); reuseItem.transform.SetParent(scrollRect.content.transform, false); UpdateItem(reuseItem, index); if (ScrollDirection == Direction.Vertical) { reuseItem.Top = (itemsLinkedList.Count > 0 ? itemsLinkedList.Last.Value.Bottom - Spacing : 0); reuseItem.SetOffsetHorizontal(0, 0); } else if (ScrollDirection == Direction.Horizontal) { reuseItem.Left = (itemsLinkedList.Count > 0 ? itemsLinkedList.Last.Value.Right + Spacing : 0); reuseItem.SetOffsetVertical(0, 0); } itemsLinkedList.AddLast(reuseItem); }