/// <summary> /// 更新每一个row的所有单元格 /// </summary> /// <param name="cellIndex">单元格序列</param> /// <param name="scrollingPositive">正反向</param> private void UpdateContent(int cellIndex, bool scrollingPositive) { int index = scrollingPositive ? ((cellIndex - 1) * NUMBER_OF_COLUMNS) + (visibleCellsTotalCount) : (cellIndex * NUMBER_OF_COLUMNS); LinkedListNode <GameObject> tempCell = null; int currentDataIndex = 0; for (int i = 0; i < NUMBER_OF_COLUMNS; i++) { this.FreeCell(scrollingPositive); tempCell = GetCellFromPool(scrollingPositive); currentDataIndex = index + i; PositionCell(tempCell.Value, index + i); ScrollViewCell scrollableCell = tempCell.Value.GetComponent <ScrollViewCell>(); if (currentDataIndex >= 0 && currentDataIndex < allCellsData.Count) { scrollableCell.Init(this, allCellsData[currentDataIndex], currentDataIndex); if (onCellInit != null) { onCellInit(scrollableCell, currentDataIndex); } } else { scrollableCell.Init(this, null, currentDataIndex); //if (onCellInit != null) //{ // onCellInit(null, currentDataIndex); //} } scrollableCell.ConfigureCell(); if (onCellConfig != null) { onCellConfig(currentDataIndex); } scrollableCell.ChooseCell(selectedIndex.Contains(currentDataIndex)); } }
/// <summary> /// 刷新Content /// </summary> void UpdateView(IList cellDataList) { if (cellDataList == null) { return; } if (cellsInUse.Count > 0) { foreach (var cell in cellsInUse) { localCellsPool.AddLast(cell); } cellsInUse.Clear(); } previousInitialIndex = 0; initialIndex = 0; content.gameObject.SetActive(true); LinkedListNode <GameObject> tempCell = null; allCellsData = cellDataList; if (horizontal) { content.sizeDelta = new Vector2((allCellsData.Count + NUMBER_OF_COLUMNS - 1) / NUMBER_OF_COLUMNS * cellWidth, content.sizeDelta.y); } else { content.sizeDelta = new Vector2(cellWidth * NUMBER_OF_COLUMNS, (allCellsData.Count + NUMBER_OF_COLUMNS - 1) / NUMBER_OF_COLUMNS * cellHeight); } int currentDataIndex = 0; for (int i = 0; i < visibleCellsTotalCount; i++) { tempCell = GetCellFromPool(true); if (tempCell == null || tempCell.Value == null) { continue; } currentDataIndex = i + initialIndex * NUMBER_OF_COLUMNS; PositionCell(tempCell.Value, currentDataIndex); tempCell.Value.SetActive(true); ScrollViewCell scrollableCell = tempCell.Value.GetComponent <ScrollViewCell>(); if (currentDataIndex < cellDataList.Count) { scrollableCell.Init(this, cellDataList[i], currentDataIndex); if (onCellInit != null) { onCellInit(scrollableCell, currentDataIndex); } } else { scrollableCell.Init(this, null, currentDataIndex); //if (onCellInit != null) //{ // onCellInit(null, currentDataIndex); //} } scrollableCell.ConfigureCell(); if (onCellConfig != null) { onCellConfig(currentDataIndex); } scrollableCell.ChooseCell(selectedIndex.Contains(currentDataIndex)); } }