LoopStaggeredGridViewItem OnGetItemByIndex(LoopStaggeredGridView listView, int index) { if (index < 0) { return(null); } ItemData itemData = DataSourceMgr.Get.GetItemDataByIndex(index); if (itemData == null) { return(null); } LoopStaggeredGridViewItem item = listView.NewListViewItem("ItemPrefab1"); ListItem5 itemScript = item.GetComponent <ListItem5>(); if (item.IsInitHandlerCalled == false) { item.IsInitHandlerCalled = true; itemScript.Init(); } itemScript.SetItemData(itemData, index); float itemWidth = 390 + mItemWidthArrayForDemo[index % mItemWidthArrayForDemo.Length] * 10f; item.CachedRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, itemWidth); return(item); }
void InitItemPool() { foreach (StaggeredGridItemPrefabConfData data in mItemPrefabDataList) { if (data.mItemPrefab == null) { Debug.LogError("A item prefab is null "); continue; } string prefabName = data.mItemPrefab.name; if (mItemPoolDict.ContainsKey(prefabName)) { Debug.LogError("A item prefab with name " + prefabName + " has existed!"); continue; } RectTransform rtf = data.mItemPrefab.GetComponent <RectTransform>(); if (rtf == null) { Debug.LogError("RectTransform component is not found in the prefab " + prefabName); continue; } AdjustAnchor(rtf); AdjustPivot(rtf); LoopStaggeredGridViewItem tItem = data.mItemPrefab.GetComponent <LoopStaggeredGridViewItem>(); if (tItem == null) { data.mItemPrefab.AddComponent <LoopStaggeredGridViewItem>(); } StaggeredGridItemPool pool = new StaggeredGridItemPool(); pool.Init(data.mItemPrefab, data.mPadding, data.mInitCreateCount, mContainerTrans); mItemPoolDict.Add(prefabName, pool); mItemPoolList.Add(pool); } }
public LoopStaggeredGridViewItem GetItem() { mCurItemIdCount++; LoopStaggeredGridViewItem tItem = null; if (mTmpPooledItemList.Count > 0) { int count = mTmpPooledItemList.Count; tItem = mTmpPooledItemList[count - 1]; mTmpPooledItemList.RemoveAt(count - 1); tItem.gameObject.SetActive(true); } else { int count = mPooledItemList.Count; if (count == 0) { tItem = CreateItem(); } else { tItem = mPooledItemList[count - 1]; mPooledItemList.RemoveAt(count - 1); tItem.gameObject.SetActive(true); } } tItem.Padding = mPadding; tItem.ItemId = mCurItemIdCount; return(tItem); }
private LoopStaggeredGridViewItem OnGetItemByIndex( LoopStaggeredGridView listView, int index) { if (index < 0) { return((LoopStaggeredGridViewItem)null); } ItemData itemDataByIndex = DataSourceMgr.Get.GetItemDataByIndex(index); if (itemDataByIndex == null) { return((LoopStaggeredGridViewItem)null); } LoopStaggeredGridViewItem staggeredGridViewItem = listView.NewListViewItem("ItemPrefab0"); ListItem5 component = (ListItem5)((Component)staggeredGridViewItem).GetComponent <ListItem5>(); if (!staggeredGridViewItem.IsInitHandlerCalled) { staggeredGridViewItem.IsInitHandlerCalled = true; component.Init(); } component.SetItemData(itemDataByIndex, index); float num = (float)(300.0 + (double)this.mItemHeightArrayForDemo[index % this.mItemHeightArrayForDemo.Length] * 10.0); staggeredGridViewItem.CachedRectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis) 1, num); return(staggeredGridViewItem); }
public LoopStaggeredGridViewItem GetNewItemByGroupAndIndex( int groupIndex, int indexInGroup) { if (indexInGroup < 0) { return((LoopStaggeredGridViewItem)null); } if (this.mItemTotalCount == 0) { return((LoopStaggeredGridViewItem)null); } List <int> itemIndexMap = this.mItemGroupList[groupIndex].ItemIndexMap; int count1 = itemIndexMap.Count; if (count1 > indexInGroup) { int num = itemIndexMap[indexInGroup]; LoopStaggeredGridViewItem staggeredGridViewItem = this.mOnGetItemByItemIndex(this, num); if (Object.op_Equality((Object)staggeredGridViewItem, (Object)null)) { return((LoopStaggeredGridViewItem)null); } staggeredGridViewItem.StartPosOffset = this.mLayoutParam.mCustomColumnOrRowOffsetArray[groupIndex]; staggeredGridViewItem.ItemIndexInGroup = indexInGroup; staggeredGridViewItem.ItemIndex = num; staggeredGridViewItem.ItemCreatedCheckFrameCount = this.mListUpdateCheckFrameCount; return(staggeredGridViewItem); } if (count1 != indexInGroup) { return((LoopStaggeredGridViewItem)null); } int count2 = this.mItemIndexDataList.Count; if (count2 >= this.mItemTotalCount) { return((LoopStaggeredGridViewItem)null); } int num1 = count2; LoopStaggeredGridViewItem staggeredGridViewItem1 = this.mOnGetItemByItemIndex(this, num1); if (Object.op_Equality((Object)staggeredGridViewItem1, (Object)null)) { return((LoopStaggeredGridViewItem)null); } itemIndexMap.Add(num1); this.mItemIndexDataList.Add(new ItemIndexData() { mGroupIndex = groupIndex, mIndexInGroup = indexInGroup }); staggeredGridViewItem1.StartPosOffset = this.mLayoutParam.mCustomColumnOrRowOffsetArray[groupIndex]; staggeredGridViewItem1.ItemIndexInGroup = indexInGroup; staggeredGridViewItem1.ItemIndex = num1; staggeredGridViewItem1.ItemCreatedCheckFrameCount = this.mListUpdateCheckFrameCount; return(staggeredGridViewItem1); }
public LoopStaggeredGridViewItem GetNewItemByGroupAndIndex(int groupIndex, int indexInGroup) { if (indexInGroup < 0) { return(null); } if (mItemTotalCount == 0) { return(null); } LoopStaggeredGridViewItem newItem = null; int index = 0; List <int> mItemIndexMap = mItemGroupList[groupIndex].ItemIndexMap; int count = mItemIndexMap.Count; if (count > indexInGroup) { index = mItemIndexMap[indexInGroup]; newItem = mOnGetItemByItemIndex(this, index); if (newItem == null) { return(null); } newItem.StartPosOffset = mLayoutParam.mCustomColumnOrRowOffsetArray[groupIndex]; newItem.ItemIndexInGroup = indexInGroup; newItem.ItemIndex = index; newItem.ItemCreatedCheckFrameCount = mListUpdateCheckFrameCount; return(newItem); } if (count != indexInGroup) { return(null); } int curMaxCreatedItemIndexCount = mItemIndexDataList.Count; if (curMaxCreatedItemIndexCount >= mItemTotalCount) { return(null); } index = curMaxCreatedItemIndexCount; newItem = mOnGetItemByItemIndex(this, index); if (newItem == null) { return(null); } mItemIndexMap.Add(index); ItemIndexData indexData = new ItemIndexData(); indexData.mGroupIndex = groupIndex; indexData.mIndexInGroup = indexInGroup; mItemIndexDataList.Add(indexData); newItem.StartPosOffset = mLayoutParam.mCustomColumnOrRowOffsetArray[groupIndex]; newItem.ItemIndexInGroup = indexInGroup; newItem.ItemIndex = index; newItem.ItemCreatedCheckFrameCount = mListUpdateCheckFrameCount; return(newItem); }
public void Init(GameObject prefabObj, float padding, int createCount, RectTransform parent) { mPrefabObj = prefabObj; mPrefabName = mPrefabObj.name; mInitCreateCount = createCount; mPadding = padding; mItemParent = parent; mPrefabObj.SetActive(false); for (int i = 0; i < mInitCreateCount; ++i) { LoopStaggeredGridViewItem tViewItem = CreateItem(); RecycleItemReal(tViewItem); } }
public void RecycleItemTmp(LoopStaggeredGridViewItem item) { if (Object.op_Equality((Object)item, (Object)null) || string.IsNullOrEmpty(item.ItemPrefabName)) { return; } StaggeredGridItemPool staggeredGridItemPool = (StaggeredGridItemPool)null; if (!this.mItemPoolDict.TryGetValue(item.ItemPrefabName, out staggeredGridItemPool)) { return; } staggeredGridItemPool.RecycleItem(item); }
public LoopStaggeredGridViewItem CreateItem() { GameObject go = GameObject.Instantiate <GameObject>(mPrefabObj, Vector3.zero, Quaternion.identity, mItemParent); go.SetActive(true); RectTransform rf = go.GetComponent <RectTransform>(); rf.localScale = Vector3.one; rf.anchoredPosition3D = Vector3.zero; rf.localEulerAngles = Vector3.zero; LoopStaggeredGridViewItem tViewItem = go.GetComponent <LoopStaggeredGridViewItem>(); tViewItem.ItemPrefabName = mPrefabName; tViewItem.StartPosOffset = 0; return(tViewItem); }
public LoopStaggeredGridViewItem CreateItem() { GameObject gameObject = (GameObject)Object.Instantiate <GameObject>((M0)this.mPrefabObj, Vector3.get_zero(), Quaternion.get_identity(), (Transform)this.mItemParent); gameObject.SetActive(true); RectTransform component1 = (RectTransform)gameObject.GetComponent <RectTransform>(); ((Transform)component1).set_localScale(Vector3.get_one()); component1.set_anchoredPosition3D(Vector3.get_zero()); ((Transform)component1).set_localEulerAngles(Vector3.get_zero()); LoopStaggeredGridViewItem component2 = (LoopStaggeredGridViewItem)gameObject.GetComponent <LoopStaggeredGridViewItem>(); component2.ItemPrefabName = this.mPrefabName; component2.StartPosOffset = 0.0f; return(component2); }
public void RecycleItemTmp(LoopStaggeredGridViewItem item) { if (item == null) { return; } if (string.IsNullOrEmpty(item.ItemPrefabName)) { return; } StaggeredGridItemPool pool = null; if (mItemPoolDict.TryGetValue(item.ItemPrefabName, out pool) == false) { return; } pool.RecycleItem(item); }
//This method is used to get a new item, and the new item is a clone from the prefab named itemPrefabName. //This method is usually used in onGetItemByItemIndex. public LoopStaggeredGridViewItem NewListViewItem(string itemPrefabName) { StaggeredGridItemPool pool = null; if (mItemPoolDict.TryGetValue(itemPrefabName, out pool) == false) { return(null); } LoopStaggeredGridViewItem item = pool.GetItem(); RectTransform rf = item.GetComponent <RectTransform>(); rf.SetParent(mContainerTrans); rf.localScale = Vector3.one; rf.anchoredPosition3D = Vector3.zero; rf.localEulerAngles = Vector3.zero; item.ParentListView = this; return(item); }
public LoopStaggeredGridViewItem NewListViewItem(string itemPrefabName) { StaggeredGridItemPool staggeredGridItemPool = (StaggeredGridItemPool)null; if (!this.mItemPoolDict.TryGetValue(itemPrefabName, out staggeredGridItemPool)) { return((LoopStaggeredGridViewItem)null); } LoopStaggeredGridViewItem staggeredGridViewItem = staggeredGridItemPool.GetItem(); RectTransform component = (RectTransform)((Component)staggeredGridViewItem).GetComponent <RectTransform>(); ((Transform)component).SetParent((Transform)this.mContainerTrans); ((Transform)component).set_localScale(Vector3.get_one()); component.set_anchoredPosition3D(Vector3.get_zero()); ((Transform)component).set_localEulerAngles(Vector3.get_zero()); staggeredGridViewItem.ParentListView = this; return(staggeredGridViewItem); }
void RecycleItemReal(LoopStaggeredGridViewItem item) { item.gameObject.SetActive(false); mPooledItemList.Add(item); }
public void RecycleItem(LoopStaggeredGridViewItem item) { mTmpPooledItemList.Add(item); }
private void RecycleItemReal(LoopStaggeredGridViewItem item) { ((Component)item).get_gameObject().SetActive(false); this.mPooledItemList.Add(item); }