// Create (or unpool) an item
        private void CreateItemAtIndex(int index)
        {
            RecycledListItem item;

            if (pooledItems.Count > 0)
            {
                item = pooledItems.Pop();
                item.gameObject.SetActive(true);
            }
            else
            {
                item = adapter.CreateItem(contentTransform);
                item.SetAdapter(adapter);
            }

            // Reposition the item
            ((RectTransform)item.transform).anchoredPosition = new Vector2(0f, -index * itemHeight);

            // To access this item easily in the future, add it to the dictionary
            items[index] = item;
        }
Exemple #2
0
        // Create (or unpool) an item
        private void CreateItemAtIndex(int index)
        {
            ListItem item;

            if (pooledItems.Count > 0)
            {
                item = pooledItems.Pop();
                item.gameObject.SetActive(true);
            }
            else
            {
                item = adapter.CreateItem();
                item.transform.SetParent(contentTransform, false);
                item.SetAdapter(adapter);
            }

            // Reposition the item
            item.transform.localPosition = new Vector3(1f, -index * itemHeight, 0f);

            // To access this item easily in the future, add it to the dictionary
            items[index] = item;
        }