/// <summary> /// 选中某单元格 /// </summary> /// <param name="dataIndex">单元格的dataIndex</param> /// <param name="multip">是否开启多选模式(多选模式下具有反选功能!)</param> public void SelectCell(int dataIndex, bool multip = false) { int index = selectedIndex.FindIndex(delegate(int temp) { return(temp == dataIndex); }); if (index != -1) { //反选 if (multip) { selectedIndex.RemoveAt(index); } } else { if (!multip) { selectedIndex.Clear(); } selectedIndex.Add(dataIndex); } foreach (GameObject cell in cellsInUse) { ScrollViewCell scrollableCell = cell.GetComponent <ScrollViewCell>(); scrollableCell.ChooseCell(selectedIndex.Contains(scrollableCell.DataIndex)); } }
/// <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)); } }