示例#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);
     }
 }
示例#2
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);
        }
示例#3
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);
        }