//-------∽-★-∽------∽-★-∽--------∽-★-∽列表项相关∽-★-∽--------∽-★-∽------∽-★-∽--------// //创建列表项 protected GameObject CreateItem(int index_) { if (m_index2item.ContainsKey(index_)) { return(m_index2item[index_]); } GameObject item; if (m_itemPool.Count > 0) { item = ListUtil.Pop(m_itemPool); //先从池里拿 } else { item = GameObjUtil.Instantiate(m_itemTemp); GameObjUtil.ChangeParent(item, m_contentGo); } m_index2item[index_] = item; item.SetActive(true); item.name = "item(" + index_ + ")"; LayItem(index_, item); return(item); }
void ShowItemsFrom(int begin_, int end_, bool force_) { if (m_begin == begin_ && m_end == end_ && !force_) { return; } m_begin = begin_; m_end = end_; __addList.Clear(); __delList.Clear(); //记录需要增加的序号 for (int i = begin_; i <= end_; ++i) { if (!m_index2item.ContainsKey(i)) { __addList.Add(i); } } //记录需要移除的序号 foreach (var kvp in m_index2item) { if (kvp.Key < begin_ || kvp.Key > end_) { __delList.Add(kvp.Key); } } GameObject item; int index; int delIndex; for (int i = 0; i < __addList.Count; ++i) { index = __addList[i]; if (__delList.Count > 0) { //先从移除列表里面取 delIndex = ListUtil.Pop(__delList); item = ChangeItemIndex(delIndex, index); } else { item = CreateItem(index); } SetItemData(item, index, m_dataList[index]); } if (__delList.Count > 0) { //还有要删除的 for (int i = 0; i < __delList.Count; ++i) { index = __delList[i]; RecyleItem(index); } } __addList.Clear(); __delList.Clear(); }