private IEnumerator AddItemsAsync() { StoreAllItem(); m_scrollViewDrag.enabled = false; for (int i = 0; i < m_maxArrangeNum; i++) { for (int j = 0; j < maxPerLine; j++) { if (i * maxPerLine + j >= m_datas.Count) { break; } LoopGridBaseItem item = AddOneItem(i, j); if (m_items.Count - 1 < i) { m_items.Add(new List <LoopGridBaseItem>()); } m_items[i].Add(item); yield return(null); } } m_scrollViewDrag.enabled = true; m_isNotNeedAsync = true; m_addItemTimer = null; }
/// <summary> /// 某个数据发生变化,直接改变数据,然后调用这个函数进行重新填充(比如折叠的item展开) /// 特点不会把scroll重置到原始状态 /// </summary> public void RefreshData() { int dataArrangeNum = Mathf.CeilToInt((float)m_datas.Count / (float)maxPerLine); bool preIsLoop = m_panel.onClipMove == OnPanelLoopClipMove; bool curIsLoop = dataArrangeNum >= m_fillCount + m_cacheNum; //调整item数量 if (preIsLoop && curIsLoop) { m_dataArrangeNum = dataArrangeNum; // 把所有的ITEM遍历一遍,重新根据变化的数据填值 bool isMove = false; for (int i = m_items.Count - 1; i >= 0; i--) { List <LoopGridBaseItem> list = m_items[i]; for (int j = list.Count - 1; j >= 0; j--) { LoopGridBaseItem item = list[j]; isMove = !item.UpdateItem(); if (isMove) { m_forwardCacheNum = m_forwardCacheNum - (m_cacheNum - 1); MoveToIndex(Mathf.Max(0, m_datas.Count - m_fillCount * maxPerLine)); m_forwardCacheNum = m_forwardCacheNum + (m_cacheNum - 1); } } } } else { ResetToBegin(); } }
private void MoveGridItem(bool isTopToBottom, bool isMoveForward) { List <LoopGridBaseItem> items; // 判断是否是 上(左)移动到下(右) int curIndex; int itemIndex; int sign; if (isTopToBottom) { curIndex = m_maxIndex + 1; itemIndex = 0; sign = 1; } else { curIndex = m_minIndex - 1; itemIndex = m_items.Count - 1; sign = -1; } items = m_items[itemIndex]; int targetIndex = itemIndex == 0 ? m_items.Count - 1 : 0; m_items.Remove(items); m_items.Insert(targetIndex, items); for (int i = 0; i < items.Count; i++) { if (curIndex * maxPerLine + i < 0) { break; } if (curIndex * maxPerLine + i > m_datas.Count - 1) { break; } LoopGridBaseItem item = items[i]; item.FillItem(m_datas, curIndex * maxPerLine + i, curIndex, i); } m_minIndex += sign; m_maxIndex += sign; if (isMoveForward) { m_forwardCacheNum -= sign; } }
private LoopGridBaseItem AddOneItem(int gridIndex, int lineIndex) { GameObject go = GetGridItem(); LoopGridBaseItem item = go.GetComponent(m_loopGridType) as LoopGridBaseItem; if (item == null) { item = go.AddComponent(m_loopGridType) as LoopGridBaseItem; item.grid = this; item.SetFirstItemData(m_datas, gridIndex * maxPerLine + lineIndex); item.FindItem(); } item.transform.parent = transform; item.transform.localScale = Vector3.one; item.gameObject.SetActive(true); item.FillItem(m_datas, gridIndex * maxPerLine + lineIndex, gridIndex, lineIndex); return(item); }
private void AddItems() { StoreAllItem(); for (int i = 0; i < m_maxArrangeNum; i++) { for (int j = 0; j < maxPerLine; j++) { if (i * maxPerLine + j >= m_datas.Count) { break; } LoopGridBaseItem item = AddOneItem(i, j); if (m_items.Count - 1 < i) { m_items.Add(new List <LoopGridBaseItem>()); } m_items[i].Add(item); } } }