Пример #1
0
        public LoopGridViewItem GetItem()
        {
            mCurItemIdCount++;
            LoopGridViewItem 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.ItemId = mCurItemIdCount;
            return(tItem);
        }
Пример #2
0
 public void RecycleItem(LoopGridViewItem item)
 {
     item.PrevItem = null;
     item.NextItem = null;
     // 按序回收
     mTmpPooledItemList.Insert(0, item);
 }
Пример #3
0
 public void Init(GameObject prefabObj, int createCount, RectTransform parent)
 {
     mPrefabObj       = prefabObj;
     mPrefabName      = mPrefabObj.name;
     mInitCreateCount = createCount;
     mItemParent      = parent;
     mPrefabObj.SetActive(false);
     for (int i = 0; i < mInitCreateCount; ++i)
     {
         LoopGridViewItem tViewItem = CreateItem();
         RecycleItemReal(tViewItem);
     }
 }
Пример #4
0
        public LoopGridViewItem GetItemByRow(int row)
        {
            LoopGridViewItem cur = mFirst;

            while (cur != null)
            {
                if (cur.Row == row)
                {
                    return(cur);
                }
                cur = cur.NextItem;
            }
            return(null);
        }
Пример #5
0
        public LoopGridViewItem GetItemByColumn(int column)
        {
            LoopGridViewItem cur = mFirst;

            while (cur != null)
            {
                if (cur.Column == column)
                {
                    return(cur);
                }
                cur = cur.NextItem;
            }
            return(null);
        }
Пример #6
0
        public void Clear()
        {
            LoopGridViewItem current = mFirst;

            while (current != null)
            {
                current.PrevItem = null;
                current.NextItem = null;
                current          = current.NextItem;
            }
            mFirst = null;
            mLast  = null;
            mCount = 0;
        }
Пример #7
0
        public LoopGridViewItem 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;
            LoopGridViewItem tViewItem = go.GetComponent <LoopGridViewItem>();

            tViewItem.ItemPrefabName = mPrefabName;
            return(tViewItem);
        }
Пример #8
0
        public LoopGridViewItem RemoveLast()
        {
            LoopGridViewItem ret = mLast;

            if (mFirst == null)
            {
                return(ret);
            }
            if (mFirst == mLast)
            {
                mFirst = null;
                mLast  = null;
                --mCount;
                return(ret);
            }
            mLast          = mLast.PrevItem;
            mLast.NextItem = null;
            --mCount;
            return(ret);
        }
Пример #9
0
 public void AddFirst(LoopGridViewItem newItem)
 {
     newItem.PrevItem = null;
     newItem.NextItem = null;
     if (mFirst == null)
     {
         mFirst          = newItem;
         mLast           = newItem;
         mFirst.PrevItem = null;
         mFirst.NextItem = null;
         mCount++;
     }
     else
     {
         mFirst.PrevItem  = newItem;
         newItem.PrevItem = null;
         newItem.NextItem = mFirst;
         mFirst           = newItem;
         mCount++;
     }
 }
Пример #10
0
 public void ReplaceItem(LoopGridViewItem curItem, LoopGridViewItem newItem)
 {
     newItem.PrevItem = curItem.PrevItem;
     newItem.NextItem = curItem.NextItem;
     if (newItem.PrevItem != null)
     {
         newItem.PrevItem.NextItem = newItem;
     }
     if (newItem.NextItem != null)
     {
         newItem.NextItem.PrevItem = newItem;
     }
     if (mFirst == curItem)
     {
         mFirst = newItem;
     }
     if (mLast == curItem)
     {
         mLast = newItem;
     }
 }
Пример #11
0
 void RecycleItemReal(LoopGridViewItem item)
 {
     item.gameObject.SetActive(false);
     mPooledItemList.Add(item);
 }