static List <IScrollableCell <T> > CreateCellList <T>(int cellNum, GameObject cellPrefab, List <T> dataList, Transform cellRoot) { List <IScrollableCell <T> > result = new List <IScrollableCell <T> >(); for (int i = 0; i < cellNum; i++) { if (i >= dataList.Count) { continue; } IScrollableCell <T> cell = GameObject.Instantiate(cellPrefab).GetComponent <IScrollableCell <T> >(); cell.SetValue(dataList[i]); Transform cellTransform = cell.transform; cellTransform.SetParent(cellRoot); cellTransform.localScale = Vector3.one; cellTransform.rotation = cellRoot.rotation; result.Add(cell); } return(result); }
List <IScrollableCell <T> > GenerateCellList <T>(GameObject cellPrefab, List <T> dataList, Transform cellRoot, out IDisposable cellDisposable) { DisposableBundle disposable = new DisposableBundle(); var rootTransform = GetComponent <RectTransform>(); int cellNum = 0; switch (_scrollType) { case ScrollType.Horizontal: cellNum = (Mathf.CeilToInt(rootTransform.rect.width / _cellSize.x) + 1) * _columnLimit; break; case ScrollType.Vertical: cellNum = (Mathf.CeilToInt(rootTransform.rect.height / _cellSize.y) + 1) * _columnLimit; break; } List <IScrollableCell <T> > result = new List <IScrollableCell <T> >(); for (int i = 0; i < cellNum; i++) { if (i >= dataList.Count) { continue; } var cellObject = GameObject.Instantiate(cellPrefab); IScrollableCell <T> cell = cellObject.GetComponent <IScrollableCell <T> >(); cell.SetValue(dataList[i]); Transform cellTransform = cell.transform; cellTransform.SetParent(cellRoot); cellTransform.localScale = Vector3.one; cellTransform.rotation = cellRoot.rotation; result.Add(cell); disposable.Add(new GameObjectDisposable(cellObject)); } cellDisposable = disposable; return(result); }