private void RecoverItem(LoopScrollItem item) { item.gameObject.SetActive(false); mItemList.Remove(item); mItemQueue.Enqueue(item); mItemIndexDic[item] = INVALIID_START_INDEX; }
private void OnValueChanged(Vector2 vec) { int curmStartIndex = GetmStartIndex(); if ((mStartIndex != curmStartIndex) && (curmStartIndex > INVALIID_START_INDEX)) { mStartIndex = curmStartIndex; for (int i = mItemList.Count - 1; i >= 0; i--) { mChangingItem = mItemList[i]; int index = mItemIndexDic[mChangingItem]; if (index < mStartIndex || index > (mStartIndex + mCreateCount - 1)) { RecoverItem(mChangingItem); } else { } } for (int i = mStartIndex; i < mStartIndex + mCreateCount; i++) { if (i >= mDataCount) { break; } else { } bool isExist = false; for (int j = 0; j < mItemList.Count; j++) { mChangingItem = mItemList[j]; int index = mItemIndexDic[mChangingItem]; if (index == i) { isExist = true; break; } else { } } if (isExist) { continue; } else { } CreateItem(i); } } }
private void OnDestroy() { mScrollRect = default; mContentRectTrans = default; mUpdateCell = default; mUpdateItem = default; m_PrefabItem = default; mPrefabItem = default; mChangingItem = default; Utils.Reclaim(ref mItemData); Utils.Reclaim(ref mItemList); Utils.Reclaim(ref mItemQueue); Utils.Reclaim(ref mItemIndexDic); }
public void InitView(ref List <ILoopScrollItemData> infos, LoopScrollItem itemRenderer, float padding = 0f, Action <LoopScrollItem, int> onUpdateCell = default) { mItemData = infos; mUpdateCell += UpdateItemInfo; if (onUpdateCell != default) { mUpdateCell += onUpdateCell; } else { } Show(infos.Count, itemRenderer, padding); }
public void UpdateList() { if (mUpdateCell != default) { int max = mItemList == default ? 0 : mItemList.Count; for (int i = 0; i < max; i++) { mUpdateItem = mItemList[i]; int index = mItemIndexDic[mUpdateItem]; mUpdateCell?.Invoke(mUpdateItem, index); } } else { } }
private void Show(int dataCount, LoopScrollItem itemRenderer, float padding = 0f) { mDataCount = dataCount; mCellPadding = padding; mPrefabItem = (m_PrefabItem == default && itemRenderer != default) ? itemRenderer : m_PrefabItem; mItemList = new List <LoopScrollItem>(); mItemQueue = new Queue <LoopScrollItem>(); mItemIndexDic = new Dictionary <LoopScrollItem, int>(); if (mScrollRect == default) { mScrollRect = GetComponent <ScrollRect>(); mContentRectTrans = mScrollRect.content; } else { } mScrollRectSize = mScrollRect.GetComponent <RectTransform>().sizeDelta; mCellSize = itemRenderer.GetComponent <RectTransform>().sizeDelta; mStartIndex = 0; mCreateCount = 0; mMaxCount = GetMaxCount(); if (mScrollRect.horizontal) { mContentRectTrans.anchorMin = new Vector2(m_ContentAnchorH.x, m_ContentAnchorH.y); mContentRectTrans.anchorMax = new Vector2(m_ContentAnchorH.width, m_ContentAnchorH.height); } else { mContentRectTrans.anchorMin = new Vector2(m_ContentAnchorV.x, m_ContentAnchorV.y); mContentRectTrans.anchorMax = new Vector2(m_ContentAnchorV.width, m_ContentAnchorV.height); } mScrollRect.onValueChanged.RemoveAllListeners(); mScrollRect.onValueChanged.AddListener(OnValueChanged); ResetSize(dataCount); }
private void UpdateItemInfo(LoopScrollItem item, int index) { ILoopScrollItemData info = mItemData[index]; info.FillInfoToItem(ref item); }