Exemplo n.º 1
0
        protected virtual UIListItem GetItem(int index)
        {
            if (index < _itemList.Count)
            {
                return(_itemList[index]);
            }
            else
            {
                RectTransform newItem = CreateItem();
                newItem.gameObject.SetActive(true);
                newItem.name = "Item " + index.ToString();

                UIListItem item = newItem.GetComponent <UIListItem>();
                _itemList.Add(item);

                return(item);
            }
        }
Exemplo n.º 2
0
        public virtual void RepositionItems()
        {
            if (_startIndex > _data.Count - PooledItemCount)
            {
                return;
            }

            for (int i = _startIndex; i < _startIndex + PooledItemCount; ++i)
            {
                if (i < 0 || i >= _data.Count)
                {
                    continue;
                }

                UIListItem item = GetItem(i - _startIndex);  // 需要减去_startIndex,因为GetItem最大只能是PooledItemCount-1
                item.CachedGameObject.name = "Item " + i.ToString();
                item.CachedRectTransform.anchoredPosition = GetItemAnchorPostion(i);
                item.UpdateItem(i, _data[i]);
            }
        }