public int findItem(int nType, RectTransform content) { int itemKey; GameObject cItem; PooList pl; if (poolMap.TryGetValue(nType, out pl)) { if (pl.unUseList.Count > 0) { itemKey = pl.GetItem(); cItem = pl.keyMap[itemKey]; } else { cItem = createItem(nType); itemKey = ++allIdKey; pl.AppendItem(itemKey, cItem); cItem.transform.SetParent(content); } } else { pl = new PooList(); cItem = createItem(nType); itemKey = ++allIdKey; pl.AppendItem(itemKey, cItem); cItem.transform.SetParent(content); poolMap[nType] = pl; } cItem.SetActive(true); return(itemKey); }
public void recycleItem(int nType, GameObject item) { PooList pl; item.SetActive(false); if (poolMap.TryGetValue(nType, out pl)) { pl.list.Push(item); } else { pl = new PooList(); pl.list.Push(item); poolMap[nType] = pl; } }