public override void Init() { base.Init(); // record the item size IUListItemView itemView = itemPrefab.GetComponent <IUListItemView> (); itemSize = itemView.GetItemSize(-1); // record max numbers per row/column numPerRow = m_MaxRow; numPerColumn = m_MaxCol; if (numPerRow < 1) { numPerRow = (int)(scrollRectSize.x / (itemSize.x + spacing.x)); } if (numPerColumn < 1) { numPerColumn = (int)(scrollRectSize.y / (itemSize.y + spacing.y)); } if (numPerRow < 1 || numPerColumn < 1) { Debug.LogError("ScrollRect size is too small to contain even one item"); } // to make items center aligned padding = Vector2.zero; // spawn pool for listitems lstItems = new List <GameObject> (); }
protected void RefreshListView() { // set the content size Vector2 size = GetContentSize(); RectTransform contentRectTransform = content.transform as RectTransform; contentRectTransform.sizeDelta = size; // set the item postion and data int startIndex = GetStartIndex(); if (startIndex < 0) { startIndex = 0; } int showItemNum = GetCurrentShowItemNum(); for (int i = 0; i < showItemNum; ++i) { int dataIndex = startIndex + i; if (dataIndex >= lstData.Count) { break; } GameObject go = GetItemGameObject(content, i); if (false == go.activeSelf) { go.SetActive(true); } RectTransform trans = go.transform as RectTransform; trans.pivot = trans.anchorMin = trans.anchorMax = new Vector2(0.5f, 0.5f); trans.anchoredPosition = GetItemAnchorPos(dataIndex); trans.localScale = Vector3.one; IUListItemView itemView = go.GetComponent <IUListItemView>(); itemView.SetData(dataIndex, lstData[dataIndex]); } // dont show the extra items shown before HideNonuseableItems(); // set the progress: int dataCount = GetDataCount(); dataCount -= (GetMaxShowItemNum() - 2); if (dataCount < 1) { dataCount = 1; } float progress = (startIndex + 1) / (float)dataCount; progress = Mathf.Clamp01(progress); OnProgress(progress); }
public override void Init() { base.Init(); // record the item size IUListItemView itemView = itemPrefab.GetComponent <IUListItemView>(); itemSize = itemView.GetItemSize(-1); // spawn pool for listitems lstItems = new List <GameObject>(); }
public override void Init() { base.Init(); lstItems = new List <GameObject> (); itemView = itemPrefab.GetComponent <IUListItemView>(); }