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); }