Example #1
0
 void InitItemPool()
 {
     foreach (StaggeredGridItemPrefabConfData data in mItemPrefabDataList)
     {
         if (data.mItemPrefab == null)
         {
             Debug.LogError("A item prefab is null ");
             continue;
         }
         string prefabName = data.mItemPrefab.name;
         if (mItemPoolDict.ContainsKey(prefabName))
         {
             Debug.LogError("A item prefab with name " + prefabName + " has existed!");
             continue;
         }
         RectTransform rtf = data.mItemPrefab.GetComponent <RectTransform>();
         if (rtf == null)
         {
             Debug.LogError("RectTransform component is not found in the prefab " + prefabName);
             continue;
         }
         AdjustAnchor(rtf);
         AdjustPivot(rtf);
         LoopStaggeredGridViewItem tItem = data.mItemPrefab.GetComponent <LoopStaggeredGridViewItem>();
         if (tItem == null)
         {
             data.mItemPrefab.AddComponent <LoopStaggeredGridViewItem>();
         }
         StaggeredGridItemPool pool = new StaggeredGridItemPool();
         pool.Init(data.mItemPrefab, data.mPadding, data.mInitCreateCount, mContainerTrans);
         mItemPoolDict.Add(prefabName, pool);
         mItemPoolList.Add(pool);
     }
 }
        public LoopStaggeredGridViewItem GetItem()
        {
            mCurItemIdCount++;
            LoopStaggeredGridViewItem tItem = null;

            if (mTmpPooledItemList.Count > 0)
            {
                int count = mTmpPooledItemList.Count;
                tItem = mTmpPooledItemList[count - 1];
                mTmpPooledItemList.RemoveAt(count - 1);
                tItem.gameObject.SetActive(true);
            }
            else
            {
                int count = mPooledItemList.Count;
                if (count == 0)
                {
                    tItem = CreateItem();
                }
                else
                {
                    tItem = mPooledItemList[count - 1];
                    mPooledItemList.RemoveAt(count - 1);
                    tItem.gameObject.SetActive(true);
                }
            }
            tItem.Padding = mPadding;
            tItem.ItemId  = mCurItemIdCount;
            return(tItem);
        }
Example #3
0
        public LoopStaggeredGridViewItem GetNewItemByGroupAndIndex(int groupIndex, int indexInGroup)
        {
            if (indexInGroup < 0)
            {
                return(null);
            }
            if (mItemTotalCount == 0)
            {
                return(null);
            }
            LoopStaggeredGridViewItem newItem = null;
            int        index         = 0;
            List <int> mItemIndexMap = mItemGroupList[groupIndex].ItemIndexMap;
            int        count         = mItemIndexMap.Count;

            if (count > indexInGroup)
            {
                index   = mItemIndexMap[indexInGroup];
                newItem = mOnGetItemByItemIndex(this, index);
                if (newItem == null)
                {
                    return(null);
                }
                newItem.StartPosOffset             = mLayoutParam.mCustomColumnOrRowOffsetArray[groupIndex];
                newItem.ItemIndexInGroup           = indexInGroup;
                newItem.ItemIndex                  = index;
                newItem.ItemCreatedCheckFrameCount = mListUpdateCheckFrameCount;
                return(newItem);
            }
            if (count != indexInGroup)
            {
                return(null);
            }
            int curMaxCreatedItemIndexCount = mItemIndexDataList.Count;

            if (curMaxCreatedItemIndexCount >= mItemTotalCount)
            {
                return(null);
            }
            index   = curMaxCreatedItemIndexCount;
            newItem = mOnGetItemByItemIndex(this, index);
            if (newItem == null)
            {
                return(null);
            }
            mItemIndexMap.Add(index);
            ItemIndexData indexData = new ItemIndexData();

            indexData.mGroupIndex   = groupIndex;
            indexData.mIndexInGroup = indexInGroup;
            mItemIndexDataList.Add(indexData);
            newItem.StartPosOffset             = mLayoutParam.mCustomColumnOrRowOffsetArray[groupIndex];
            newItem.ItemIndexInGroup           = indexInGroup;
            newItem.ItemIndex                  = index;
            newItem.ItemCreatedCheckFrameCount = mListUpdateCheckFrameCount;
            return(newItem);
        }
 public void Init(GameObject prefabObj, float padding, int createCount, RectTransform parent)
 {
     mPrefabObj       = prefabObj;
     mPrefabName      = mPrefabObj.name;
     mInitCreateCount = createCount;
     mPadding         = padding;
     mItemParent      = parent;
     mPrefabObj.SetActive(false);
     for (int i = 0; i < mInitCreateCount; ++i)
     {
         LoopStaggeredGridViewItem tViewItem = CreateItem();
         RecycleItemReal(tViewItem);
     }
 }
        public LoopStaggeredGridViewItem CreateItem()
        {
            GameObject go = GameObject.Instantiate <GameObject>(mPrefabObj, Vector3.zero, Quaternion.identity, mItemParent);

            go.SetActive(true);
            RectTransform rf = go.GetComponent <RectTransform>();

            rf.localScale         = Vector3.one;
            rf.anchoredPosition3D = Vector3.zero;
            rf.localEulerAngles   = Vector3.zero;
            LoopStaggeredGridViewItem tViewItem = go.GetComponent <LoopStaggeredGridViewItem>();

            tViewItem.ItemPrefabName = mPrefabName;
            tViewItem.StartPosOffset = 0;
            return(tViewItem);
        }
Example #6
0
        public void RecycleItemTmp(LoopStaggeredGridViewItem item)
        {
            if (item == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(item.ItemPrefabName))
            {
                return;
            }
            StaggeredGridItemPool pool = null;

            if (mItemPoolDict.TryGetValue(item.ItemPrefabName, out pool) == false)
            {
                return;
            }
            pool.RecycleItem(item);
        }
Example #7
0
        //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);
        }
 void RecycleItemReal(LoopStaggeredGridViewItem item)
 {
     item.gameObject.SetActive(false);
     mPooledItemList.Add(item);
 }
 public void RecycleItem(LoopStaggeredGridViewItem item)
 {
     mTmpPooledItemList.Add(item);
 }