平时需要做一些排行榜或者背包之类的功能时,就需要考虑生成物体的数量,因此普遍会用到对象池
这个组件就是生成一定数量的克隆体放入对象池中,使其循环利用,从而达到无限下拉的功能。
主要函数:
public virtual void Init(Action<GameObject, int> callBack, Action<GameObject, int> onClickCallBack)
{
DisposeAll();
m_FuncCallBackFunc = callBack;
if (onClickCallBack != null)
{
m_FuncOnClickCallBack = onClickCallBack;
}
if (m_isInited)
return;
m_Content = this.GetComponent<ScrollRect>().content.gameObject;
if (m_CellGameObject == null)
{
m_CellGameObject = m_Content.transform.GetChild(0).gameObject;
}
/* Cell 处理 */
//m_CellGameObject.transform.SetParent(m_Content.transform.parent, false);
SetPoolsObj(m_CellGameObject);
RectTransform cellRectTrans = m_CellGameObject.GetComponent<RectTransform>();
cellRectTrans.pivot = new Vector2(0f, 1f);
CheckAnchor(cellRectTrans);
cellRectTrans.anchoredPosition = Vector2.zero;
cellRectTrans.localPosition = new Vector3(0, 0, 0);
//记录 Cell 信息
m_CellObjectHeight = cellRectTrans.rect.height;
m_CellObjectWidth = cellRectTrans.rect.width;
//记录 Plane 信息
rectTrans = GetComponent<RectTransform>();
Rect planeRect = rectTrans.rect;
m_PlaneHeight = planeRect.height;
m_PlaneWidth = planeRect.width;
//记录 Content 信息
m_ContentRectTrans = m_Content.GetComponent<RectTransform>();
Rect contentRect = m_ContentRectTrans.rect;
m_ContentHeight = contentRect.height;
m_ContentWidth = contentRect.width;
m_ContentRectTrans.pivot = new Vector2(0f, 1f);
//m_ContentRectTrans.sizeDelta = new Vector2 (planeRect.width, planeRect.height);