虚拟列表和循环列表提交
This commit is contained in:
76
UnityGame/Assets/Scripts/ThirdParty/LoopList/Runtime/LoopScrollRect.cs
vendored
Normal file
76
UnityGame/Assets/Scripts/ThirdParty/LoopList/Runtime/LoopScrollRect.cs
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEngine.UI
|
||||
{
|
||||
public abstract class LoopScrollRect : LoopScrollRectBase
|
||||
{
|
||||
[HideInInspector]
|
||||
[NonSerialized]
|
||||
public LoopScrollDataSource dataSource = null;
|
||||
|
||||
protected override void ProvideData(Transform transform, int index)
|
||||
{
|
||||
dataSource.ProvideData(transform, index);
|
||||
}
|
||||
|
||||
protected override RectTransform GetFromTempPool(int itemIdx)
|
||||
{
|
||||
RectTransform nextItem = null;
|
||||
if (deletedItemTypeStart > 0)
|
||||
{
|
||||
deletedItemTypeStart--;
|
||||
nextItem = m_Content.GetChild(0) as RectTransform;
|
||||
nextItem.SetSiblingIndex(itemIdx - itemTypeStart + deletedItemTypeStart);
|
||||
}
|
||||
else if (deletedItemTypeEnd > 0)
|
||||
{
|
||||
deletedItemTypeEnd--;
|
||||
nextItem = m_Content.GetChild(m_Content.childCount - 1) as RectTransform;
|
||||
nextItem.SetSiblingIndex(itemIdx - itemTypeStart + deletedItemTypeStart);
|
||||
}
|
||||
else
|
||||
{
|
||||
nextItem = prefabSource.GetObject(itemIdx).transform as RectTransform;
|
||||
nextItem.transform.SetParent(m_Content, false);
|
||||
nextItem.gameObject.SetActive(true);
|
||||
}
|
||||
ProvideData(nextItem, itemIdx);
|
||||
return nextItem;
|
||||
}
|
||||
|
||||
protected override void ReturnToTempPool(bool fromStart, int count)
|
||||
{
|
||||
if (fromStart)
|
||||
deletedItemTypeStart += count;
|
||||
else
|
||||
deletedItemTypeEnd += count;
|
||||
}
|
||||
|
||||
protected override void ClearTempPool()
|
||||
{
|
||||
Debug.Assert(m_Content.childCount >= deletedItemTypeStart + deletedItemTypeEnd);
|
||||
if (deletedItemTypeStart > 0)
|
||||
{
|
||||
for (int i = deletedItemTypeStart - 1; i >= 0; i--)
|
||||
{
|
||||
prefabSource.ReturnObject(m_Content.GetChild(i));
|
||||
}
|
||||
deletedItemTypeStart = 0;
|
||||
}
|
||||
if (deletedItemTypeEnd > 0)
|
||||
{
|
||||
int t = m_Content.childCount - deletedItemTypeEnd;
|
||||
for (int i = m_Content.childCount - 1; i >= t; i--)
|
||||
{
|
||||
prefabSource.ReturnObject(m_Content.GetChild(i));
|
||||
}
|
||||
deletedItemTypeEnd = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user