Exemplo n.º 1
0
    public static void SetListContent <P, D>(P prefab, Transform parent, List <P> itemList, System.Collections.Generic.ICollection <D> dataList, IsItemEnabledFunc <P, D> isItemEnabledFunc, SetDataContentFunc <P, D> setContentFunc,
                                             int start = 0,
                                             int count = 0)
        where P : MonoBehaviour
    {
        if (itemList == null)
        {
            return;
        }
        if (dataList == null)
        {
            foreach (var item in itemList)
            {
                item.gameObject.SetActive(false);
            }
        }
        else
        {
            if (count == 0 || (start + count) > dataList.Count)
            {
                count = dataList.Count - start;
            }
            while (itemList.Count < count)
            {
                itemList.Add(AddChild(parent, prefab));
            }

            var emu = dataList.GetEnumerator();

            for (int i = 0; i < start && emu.MoveNext(); ++i)
            {
            }

            for (int i = 0; i < itemList.Count; ++i)
            {
                if (emu.MoveNext())
                {
                    int index = start + i;
                    var item  = itemList[i];
                    var data  = emu.Current;
                    if (isItemEnabledFunc != null)
                    {
                        if (!isItemEnabledFunc(index, data))
                        {
                            item.gameObject.SetActive(false);
                            continue;
                        }
                    }
                    itemList[i].gameObject.SetActive(true);
                    if (setContentFunc != null)
                    {
                        setContentFunc(index, item, data);
                    }
                }
                else
                {
                    itemList[i].gameObject.SetActive(false);
                }
            }
        }
    }
Exemplo n.º 2
0
 public static void SetListContent <P, D>(P prefab, Transform parent, List <P> itemList, System.Collections.Generic.ICollection <D> dataList, SetDataContentFunc <P, D> setContentFunc,
                                          int start = 0,
                                          int count = 0)
     where P : MonoBehaviour
 {
     SetListContent <P, D>(prefab, parent, itemList, dataList, null, setContentFunc, start, count);
 }