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