IEnumerator AddItemsAsync() { m_isStartFill = true; StoreAllItem(); StoreQueuePoolItem(); for (int i = 0; i < m_maxArrangeNum; i++) { for (int j = 0; j < maxPerLine; j++) { if (i * maxPerLine + j >= m_dataCount) { break; } LoopGridLuaItem item = AddOneItem(i, j); if (m_items.Count - 1 < i) { m_items.Add(new List <LoopGridLuaItem>()); } m_items[i].Add(item); UITweener ut = item.GetComponent <UITweener>(); if (ut) { ut.ResetToBeginning(); ut.PlayForward(); } else { Debug.LogError("请UI同学绑定个Tween动画控件"); } yield return(new WaitForSeconds(deltaTime)); } } m_isStartFill = false; m_timer = null; }
private void AddItems() { m_isStartFill = true; StoreAllItem(); for (int i = 0; i < m_maxArrangeNum; i++) { for (int j = 0; j < maxPerLine; j++) { if (i * maxPerLine + j >= m_dataCount) { break; } LoopGridLuaItem item = AddOneItem(i, j); if (m_items.Count - 1 < i) { m_items.Add(new List <LoopGridLuaItem>()); } m_items[i].Add(item); } } StoreQueuePoolItem(); m_isStartFill = false; }
private void CreateItemPool(GameObject itemTemplate, int poolNum) { if (m_poolGo == null) { m_poolGo = new GameObject(); m_poolGo.name = "pool"; m_poolGo.transform.parent = transform.parent; m_poolGo.transform.localScale = Vector3.one; } m_itemCOPool.Init(poolNum, CreateItemGO, Init); #if UNITY_EDITOR if (transform.childCount <= 0 && Application.isPlaying) { Debug.LogError("这个并没有使用对象池,请点击脚本齿轮上的Execute.不然手机上打开界面会变慢"); } #endif for (int i = 0, imax = transform.childCount; i < imax; i++) { GameObject go = transform.GetChild(0).gameObject; LoopGridLuaItem item = go.GetComponent <LoopGridLuaItem>(); if (item == null) { item = go.AddComponent <LoopGridLuaItem>(); } item.grid = this; m_itemCOPool.Store(go); } }
private void BindChild() { if (!m_grid.hasChild) { return; } if (m_childItems == null) { m_childItems = new List <LoopGridLuaItem>(); } else { m_childItems.Clear(); } gameObject.GetComponentsInChildren <LoopGridLuaItem>(true, m_childItems); m_childItems.Remove(this); for (int i = 0, imax = m_childItems.Count; i < imax; i++) { LoopGridLuaItem item = m_childItems[i]; item.grid = m_grid; LuaTable childBind = m_grid.CreateChildFillTable(); item.DoInitUICore(childBind); item.DoFindItem(); } }
/// <summary> /// 隐藏所有item /// </summary> public void HideAllItem() { for (int i = 0; i < m_items.Count; i++) { for (int j = 0; j < m_items[i].Count; j++) { LoopGridLuaItem item = m_items[i][j]; item.gameObject.SetActive(false); } } }
/// <summary> /// 通过索引得到Go /// </summary> public GameObject GetGameObjectByIndex(int index) { int i = Mathf.CeilToInt(index / (float)maxPerLine); int j = index - (i - 1) * maxPerLine; if (i <= m_items.Count && j <= m_items[i - 1].Count) { LoopGridLuaItem item = m_items[i - 1][j - 1]; return(item.gameObject); } return(null); }
private void DoCallChildFill() { if (m_childItems == null) { return; } for (int i = 0, imax = m_childItems.Count; i < imax; i++) { LoopGridLuaItem item = m_childItems[i]; item.FillChildItem(m_index, i, m_index * imax + i); } }
private void MoveGridItem(bool isTopToBottom) { List <LoopGridLuaItem> 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_dataCount - 1) { break; } LoopGridLuaItem item = items[i]; item.FillItem(curIndex * maxPerLine + i, curIndex, i); } m_minIndex += sign; m_maxIndex += sign; }
private bool CheckIndexOut() { bool result = false; for (int i = m_items.Count - 1; i >= 0; i--) { List <LoopGridLuaItem> list = m_items[i]; for (int j = 0, jmax = list.Count; j < jmax; j++) { LoopGridLuaItem item = list[j]; result = item.CheckIndexOutRange(); if (result) { return(true); } } } return(result); }
/// <summary> /// 某个数据发生变化,直接改变数据,然后调用这个函数进行重新填充(比如折叠的item展开) /// 特点不会把scroll重置到原始状态 /// </summary> public void RefreshData() { int dataArrangeNum = Mathf.CeilToInt((float)m_dataCount / (float)maxPerLine); bool preIsLoop = m_panel.onClipMove == OnPanelLoopClipMove; bool curIsLoop = dataArrangeNum >= m_fillCount + m_cacheNum; bool olduseAnimate = useAnimate; useAnimate = false; //调整item数量 if (m_dataArrangeNum == dataArrangeNum) { for (int i = m_items.Count - 1; i >= 0; i--) { List <LoopGridLuaItem> list = m_items[i]; for (int j = list.Count - 1; j >= 0; j--) { LoopGridLuaItem item = list[j]; item.UpdateItem(); } } } else if (preIsLoop && curIsLoop) { int tmpIndex = m_lastDataIndex; if (m_dataArrangeNum > dataArrangeNum && CheckIndexOut()) { tmpIndex = Mathf.Max(0, m_dataCount - m_fillCount * maxPerLine); } m_dataArrangeNum = dataArrangeNum; ResetToBegin(); MoveToIndex(tmpIndex); } else { m_dataArrangeNum = dataArrangeNum; ResetToBegin(); } useAnimate = olduseAnimate; }
private LoopGridLuaItem AddOneItem(int gridIndex, int lineIndex) { GameObject go = GetGridItem(); var cb = go.GetComponent <UIToggle>(); if (selectLimit == 1) { if (cb != null) { cb.group = 1024; } } else if (selectLimit > 1) { if (cb != null) { cb.group = 0; } } LoopGridLuaItem item = go.GetComponent <LoopGridLuaItem>(); if (item == null || !item.inited) { if (item == null) { item = go.AddComponent <LoopGridLuaItem>(); } item.grid = this; LuaTable bind = CreateFillTable(); item.SetFirstItemData(m_dataCount, gridIndex * maxPerLine + lineIndex); item.FindItem(bind); } item.transform.parent = transform; item.transform.localScale = itemTemplate.transform.localScale; item.gameObject.SetActive(true); item.FillItem(gridIndex * maxPerLine + lineIndex, gridIndex, lineIndex); return(item); }