예제 #1
0
파일: IUListView.cs 프로젝트: moto2002/Fish
        protected CellHandler GetUnUseCell()
        {
            for (int i = 0; i < m_CellHandlerList.Count; ++i)
            {
                if (m_CellHandlerList[i].dataIndex < 0)
                {
                    return(m_CellHandlerList[i]);
                }
            }

            CellHandler handler = new CellHandler(GameObject.Instantiate(itemPrefab, content, false) as GameObject);

            m_CellHandlerList.Add(handler);
            return(handler);
        }
예제 #2
0
파일: IUListView.cs 프로젝트: moto2002/Fish
        protected void RefreshListView()
        {
            // set the content size
            Vector2       size = GetContentSize();
            RectTransform contentRectTransform = content.transform as RectTransform;

            AdjustViewportSize(size);

            contentRectTransform.sizeDelta = size;

            // set the item postion and data
            int startIndex = GetStartIndex();

            if (startIndex < 0)
            {
                startIndex = 0;
            }

            int showItemNum = GetCurrentShowItemNum();

            ResetUnUsedCell(startIndex, startIndex + showItemNum);

            for (int i = 0; i < showItemNum; ++i)
            {
                int dataIndex = startIndex + i;
                if (dataIndex >= lstCount)
                {
                    break;
                }

                //Opt
                if (dataIndex >= m_PreDataIndexMin && dataIndex <= m_PreDataIndexMax)
                {
                    continue;
                }

                ///////////////
                CellHandler cell = GetUnUseCell();
                cell.dataIndex = dataIndex;
                cell.UpdatePosition(GetItemAnchorPos(dataIndex));
                ///////////////

/*
 *                              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;
 */
                if (m_CellRenderer != null)
                {
                    m_CellRenderer(cell.root, dataIndex);
                }
            }

            m_PreDataIndexMin = startIndex;
            m_PreDataIndexMax = startIndex + showItemNum - 1;

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