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); }
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); }
LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index) { if (index < 0) { return(null); } LoopListViewItem2 item = null; if (index == DataSourceMgr.Get.TotalItemCount) { item = listView.NewListViewItem("ItemPrefab0"); UpdateLoadingTip(item); return(item); } ItemData itemData = DataSourceMgr.Get.GetItemDataByIndex(index); if (itemData == null) { return(null); } item = listView.NewListViewItem("ItemPrefab1"); ListItem5 itemScript = item.GetComponent <ListItem5>(); if (item.IsInitHandlerCalled == false) { item.IsInitHandlerCalled = true; itemScript.Init(); } if (index == DataSourceMgr.Get.TotalItemCount - 1) { item.Padding = 0; } itemScript.SetItemData(itemData, index); return(item); }
LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index) { if (index < 0 || index >= DataSourceMgr.Get.TotalItemCount) { return(null); } ItemData itemData = DataSourceMgr.Get.GetItemDataByIndex(index); if (itemData == null) { return(null); } //get a new item. Every item can use a different prefab, the parameter of the NewListViewItem is the prefab’name. //And all the prefabs should be listed in ItemPrefabList in LoopListView2 Inspector Setting LoopListViewItem2 item = listView.NewListViewItem("ItemPrefab1"); ListItem5 itemScript = item.GetComponent <ListItem5>(); if (item.IsInitHandlerCalled == false) { item.IsInitHandlerCalled = true; itemScript.Init(); } itemScript.SetItemData(itemData, index); return(item); }
void UpdateItemPrefab() { ItemPrefabConfData tData = mLoopListView.GetItemPrefabConfData("ItemPrefab1"); GameObject prefabObj = tData.mItemPrefab; RectTransform rf = prefabObj.GetComponent <RectTransform>(); ListItem6 itemScript = prefabObj.GetComponent <ListItem6>(); float w = mLoopListView.ViewPortWidth; int count = itemScript.mItemList.Count; GameObject p0 = itemScript.mItemList[0].gameObject; RectTransform rf0 = p0.GetComponent <RectTransform>(); float w0 = rf0.rect.width; int c = Mathf.FloorToInt(w / w0); if (c == 0) { c = 1; } mItemCountPerRow = c; float padding = (w - w0 * c) / (c + 1); if (padding < 0) { padding = 0; } rf.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, w); if (c > count) { int dif = c - count; for (int i = 0; i < dif; ++i) { GameObject go = Object.Instantiate(p0, Vector3.zero, Quaternion.identity, rf); RectTransform trf = go.GetComponent <RectTransform>(); trf.localScale = Vector3.one; trf.localPosition = Vector3.zero; trf.rotation = Quaternion.identity; ListItem5 t = go.GetComponent <ListItem5>(); itemScript.mItemList.Add(t); } } else if (c < count) { int dif = count - c; for (int i = 0; i < dif; ++i) { ListItem5 go = itemScript.mItemList[itemScript.mItemList.Count - 1]; itemScript.mItemList.RemoveAt(itemScript.mItemList.Count - 1); Object.DestroyImmediate(go.gameObject); } } float curX = padding; for (int k = 0; k < itemScript.mItemList.Count; ++k) { GameObject obj = itemScript.mItemList[k].gameObject; obj.transform.localPosition = new Vector3(curX, 0, 0); curX = curX + w0 + padding; } mLoopListView.OnItemPrefabChanged("ItemPrefab1"); }
private void UpdateItemPrefab() { GameObject mItemPrefab = this.mLoopListView.GetItemPrefabConfData("ItemPrefab2").mItemPrefab; RectTransform component1 = (RectTransform)mItemPrefab.GetComponent <RectTransform>(); ListItem6 component2 = (ListItem6)mItemPrefab.GetComponent <ListItem6>(); float viewPortWidth = this.mLoopListView.ViewPortWidth; int count = component2.mItemList.Count; GameObject gameObject1 = ((Component)component2.mItemList[0]).get_gameObject(); Rect rect = ((RectTransform)gameObject1.GetComponent <RectTransform>()).get_rect(); float width = ((Rect) ref rect).get_width(); int num1 = Mathf.FloorToInt(viewPortWidth / width); if (num1 == 0) { num1 = 1; } this.mItemCountPerRow = num1; float num2 = (viewPortWidth - width * (float)num1) / (float)(num1 + 1); if ((double)num2 < 0.0) { num2 = 0.0f; } component1.SetSizeWithCurrentAnchors((RectTransform.Axis) 0, viewPortWidth); if (num1 > count) { int num3 = num1 - count; for (int index = 0; index < num3; ++index) { GameObject gameObject2 = (GameObject)Object.Instantiate <GameObject>((M0)gameObject1, Vector3.get_zero(), Quaternion.get_identity(), (Transform)component1); RectTransform component3 = (RectTransform)gameObject2.GetComponent <RectTransform>(); ((Transform)component3).set_localScale(Vector3.get_one()); component3.set_anchoredPosition3D(Vector3.get_zero()); ((Transform)component3).set_rotation(Quaternion.get_identity()); ListItem5 component4 = (ListItem5)gameObject2.GetComponent <ListItem5>(); component2.mItemList.Add(component4); } } else if (num1 < count) { int num3 = count - num1; for (int index = 0; index < num3; ++index) { ListItem5 mItem = component2.mItemList[component2.mItemList.Count - 1]; component2.mItemList.RemoveAt(component2.mItemList.Count - 1); Object.DestroyImmediate((Object)((Component)mItem).get_gameObject()); } } float num4 = num2; for (int index = 0; index < component2.mItemList.Count; ++index) { ((RectTransform)((Component)component2.mItemList[index]).get_gameObject().GetComponent <RectTransform>()).set_anchoredPosition3D(new Vector3(num4, 0.0f, 0.0f)); num4 = num4 + width + num2; } this.mLoopListView.OnItemPrefabChanged("ItemPrefab2"); }
private void LateUpdate() { this.mLoopListView.UpdateAllShownItemSnapData(); int shownItemCount = this.mLoopListView.ShownItemCount; for (int index = 0; index < shownItemCount; ++index) { LoopListViewItem2 shownItemByIndex = this.mLoopListView.GetShownItemByIndex(index); ListItem5 component = (ListItem5)((Component)shownItemByIndex).GetComponent <ListItem5>(); float num = Mathf.Clamp((float)(1.0 - (double)Mathf.Abs(shownItemByIndex.DistanceWithViewPortSnapCenter) / 700.0), 0.4f, 1f); ((CanvasGroup)component.mContentRootObj.GetComponent <CanvasGroup>()).set_alpha(num); component.mContentRootObj.get_transform().set_localScale(new Vector3(num, num, 1f)); } }
void LateUpdate() { mLoopListView.UpdateAllShownItemSnapData(); int count = mLoopListView.ShownItemCount; for (int i = 0; i < count; ++i) { LoopListViewItem2 item = mLoopListView.GetShownItemByIndex(i); ListItem5 itemScript = item.GetComponent <ListItem5>(); float scale = 1 - Mathf.Abs(item.DistanceWithViewPortSnapCenter) / 700f; scale = Mathf.Clamp(scale, 0.4f, 1); itemScript.mContentRootObj.GetComponent <CanvasGroup>().alpha = scale; itemScript.mContentRootObj.transform.localScale = new Vector3(scale, scale, 1); } }
private LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index) { if (index < 0 || index >= DataSourceMgr.Get.TotalItemCount) { return((LoopListViewItem2)null); } ItemData itemDataByIndex = DataSourceMgr.Get.GetItemDataByIndex(index); if (itemDataByIndex == null) { return((LoopListViewItem2)null); } LoopListViewItem2 loopListViewItem2 = listView.NewListViewItem("ItemPrefab1"); ListItem5 component = (ListItem5)((Component)loopListViewItem2).GetComponent <ListItem5>(); if (!loopListViewItem2.IsInitHandlerCalled) { loopListViewItem2.IsInitHandlerCalled = true; component.Init(); } component.SetItemData(itemDataByIndex, index); return(loopListViewItem2); }