/// <summary> /// 隐藏cell /// </summary> /// <param name="index"></param> /// <param name="isRebuild"></param> void HideCell(int index, bool isRebuild) { ScrollPageViewCell cellTmp = _cells.Find(i => i._index == index); if (cellTmp == null) { return; } if (!isRebuild) { // cellTmp.gameObject.SetActive(false); cellTmp.Hide(); } _cells.Remove(cellTmp); _cellCaches.Add(cellTmp); }
/// <summary> /// 从缓存中获取cell /// </summary> /// <returns></returns> ScrollPageViewCell GetCell() { ScrollPageViewCell result = null; if (_cellCaches.Count > 0) { //从caches中获取 result = _cellCaches[0]; _cellCaches.RemoveAt(0); } else { //新建 var go = Instantiate(CellSource) as GameObject; result = go.GetComponent <ScrollPageViewCell>(); } return(result); }
/// <summary> /// 显示Cell /// </summary> /// <param name="index"></param> /// <param name="isRebuild"></param> /// <param name="data"></param> void ShowCell(int index, bool isRebuild) { ScrollPageViewCell cellTmp = GetCell(); cellTmp.transform.SetParent(content); cellTmp.transform.localScale = Vector3.one; cellTmp.RectTransform.anchoredPosition3D = GetCellPos(index); if (!isRebuild) { cellTmp._index = index; cellTmp.gameObject.SetActive(true); cellTmp.Show(); if (_onRefresh != null) { _onRefresh(index, cellTmp); } } _cells.Add(cellTmp); }