示例#1
0
    //修改需实例化的cell 数量
    private void CreateAllCellInstance()
    {
        int tViewCnt     = mGridArrangeBase.GetCellsCountByViewSize();
        int tInstanceCnt = Mathf.Min(mConfig.mDataCnt, tViewCnt);

        mInstaceCellStartDataIndex = 0;
        mDataIndexList.Clear();
        mCellDic.Clear();

        List <int> tNewDataIndexList = mGridArrangeBase.GetNewDataIndexList();

        //创建cell
        int i = 0;

        for (; i < tInstanceCnt; ++i)
        {
            GameObject tCell = null;

            if (i < mCellList.Count)
            {
                tCell = mCellList[i];
                tCell.SetActive(true);
            }
            else
            {
                tCell = mConfig.CreateCell();
                tCell.SetActive(true);

                mCellList.Add(tCell);
            }

            int tDataIndex = tNewDataIndexList[i];
            mDataIndexList.Add(tDataIndex);
            mCellDic.Add(tDataIndex, tCell);

            RectTransform tRectTransform = tCell.transform as RectTransform;

            if (mCellOffsetPos.x == float.MaxValue)
            {
                mCellOffsetPos = GetCellOffsetValue(tRectTransform);
            }

            tRectTransform.anchoredPosition = GetAnchorPosByDataIndex(tDataIndex);

            mConfig.mDisplayCellAction(tDataIndex, tCell);
        }

        //隐藏多余的cell
        for (; i < mCellList.Count; ++i)
        {
            mCellList[i].SetActive(false);
        }
    }