void CreateCells() { for (int i = 0; i < rowNum * colNum; i++) { GameObject unit = GameObject.Instantiate(go); unit.name = unit.name + i; unit.transform.SetParent(pool.transform, false); (unit.transform as RectTransform).localScale = new Vector3(cellScale, cellScale, cellScale); (unit.transform as RectTransform).pivot = new Vector2(0, 1); (unit.transform as RectTransform).anchorMin = new Vector2(0, 1); (unit.transform as RectTransform).anchorMax = new Vector2(0, 1); SuperListCell cell = unit.GetComponent <SuperListCell>(); if (isAlphaIn) { cell.canvasGroup = unit.AddComponent <CanvasGroup>(); } hidePool.Add(cell); } }
private void OneAlphaInOver() { alphaInList.RemoveAt(0); if (alphaInList.Count > 0) { SuperListCell cell = alphaInList[0]; cell.AlphaIn(OneAlphaInOver); } }
public void UpdateItemAt(int _index, object _data) { data [_index] = _data; for (int i = 0; i < showPool.Count; i++) { SuperListCell cell = showPool[i]; if (cell.index == _index) { cell.SetData(_data); break; } } }
public void UpdateItemAt(int _index, object _data) { data [_index] = _data; foreach (GameObject unit in showPool) { SuperListCell cell = unit.GetComponent <SuperListCell> (); if (cell.index == _index) { cell.SetData(_data); break; } } }
public void SetSelectedIndex(int _index) { if (selectedIndex == _index) { return; } if (needSelectedIndex) { for (int i = 0; i < showPool.Count; i++) { SuperListCell cell = showPool[i]; if (cell.index == _index) { cell.SetSelected(true); } else if (cell.index == selectedIndex) { cell.SetSelected(false); } } selectedIndex = _index; } if (selectedIndex != -1 || !needSelectedIndex) { if (CellClickHandle != null) { CellClickHandle(data [_index]); } if (CellClickIndexHandle != null) { CellClickIndexHandle(_index); } } }
public void SetSelectedIndex(int _index) { if (selectedIndex == _index) { return; } if (needSelectedIndex) { foreach (GameObject unit in showPool) { SuperListCell cell = unit.GetComponent <SuperListCell> (); if (cell.index == selectedIndex) { cell.SetSelected(false); } else if (cell.index == _index) { cell.SetSelected(true); } } selectedIndex = _index; } if (selectedIndex != -1 || !needSelectedIndex) { if (CellClickHandle != null) { CellClickHandle(data [_index]); } if (CellClickIndexHandle != null) { CellClickIndexHandle(_index); } } }
void CellClick(SuperListCell _cell) { SetSelectedIndex(_cell.index); }
private void SetCellData(SuperListCell _cell, int _index) { if (!isAlphaIn) { _cell.SetData(data[_index]); } else { bool result = _cell.SetData(data[_index]); if (result) { _cell.canvasGroup.alpha = 0; int index = alphaInList.IndexOf(_cell); bool needStart = false; if (index != -1) { if (index == 0) { _cell.StopAlphaIn(); needStart = true; } alphaInList.RemoveAt(index); } alphaInList.Add(_cell); if (alphaInList.Count == 1 || needStart) { alphaInList[0].AlphaIn(OneAlphaInOver); } } else { _cell.canvasGroup.alpha = 1; int index = alphaInList.IndexOf(_cell); bool needStart = false; if (index != -1) { if (index == 0) { _cell.StopAlphaIn(); needStart = true; } alphaInList.RemoveAt(index); } if (needStart && alphaInList.Count > 0) { alphaInList[0].AlphaIn(OneAlphaInOver); } } } }
private void SetCellIndex(SuperListCell _cell, int _index) { int row; int col; float xFix = 0; float yFix = 0; if (isVertical) { row = _index / colNum; col = _index % colNum; if (insertIndexArr != null) { for (int i = 0; i < insertIndexArr.Length; i++) { if (row >= insertIndexArr[i]) { yFix += insertRectArr[i].rect.height + verticalGap; } else { break; } } } } else { col = _index / rowNum; row = _index % rowNum; if (insertIndexArr != null) { for (int i = 0; i < insertIndexArr.Length; i++) { if (col >= insertIndexArr[i]) { xFix += insertRectArr[i].rect.width + horizontalGap; } else { break; } } } } float xPos = col * (cellWidth + horizontalGap) + xFix; float yPos = -row * (cellHeight + verticalGap) - yFix; Vector2 pos = new Vector2(xPos, yPos); (_cell.transform as RectTransform).anchoredPosition = pos; _cell.index = _index; _cell.SetSelected(_index == selectedIndex); }
private void ResetPos(int _nowIndex, bool _dataHasChange, bool _insertHasChange) { // if (data.Count == 0) { // // return; // } if (isVertical) { if (_nowIndex - showIndex == colNum) { for (int i = 0; i < _nowIndex - showIndex; i++) { int newIndex = showIndex + rowNum * colNum + i; SuperListCell unit = showPool [0]; showPool.RemoveAt(0); if (newIndex < data.Count) { showPool.Add(unit); SetCellIndex(unit, newIndex); SetCellData(unit, newIndex); } else { hidePool.Add(unit); unit.transform.SetParent(pool.transform, false); } } } else if (_nowIndex - showIndex == -colNum) { for (int i = 0; i < showIndex - _nowIndex; i++) { int newIndex = showIndex - colNum + i; SuperListCell unit; if (showPool.Count == rowNum * colNum) { unit = showPool [showPool.Count - 1]; showPool.RemoveAt(showPool.Count - 1); } else { unit = hidePool [0]; hidePool.RemoveAt(0); unit.transform.SetParent(container.transform, false); } showPool.Insert(0, unit); SetCellIndex(unit, newIndex); SetCellData(unit, newIndex); } } else { List <int> tmpList = new List <int> (); for (int i = 0; i < rowNum * colNum; i++) { if (_nowIndex + i < data.Count) { tmpList.Add(_nowIndex + i); } else { break; } } SuperListCell[] newShowPool = new SuperListCell[tmpList.Count]; List <SuperListCell> replacePool = new List <SuperListCell> (); for (int i = 0; i < showPool.Count; i++) { SuperListCell unit = showPool [i]; int tmpIndex = unit.index; if (tmpList.Contains(tmpIndex)) { newShowPool [tmpList.IndexOf(tmpIndex)] = unit; if (_dataHasChange) { SetCellData(unit, tmpIndex); //如果列表数据已经发生了变化则需要在这里进行一次单元格赋值 } if (_insertHasChange) { SetCellIndex(unit, tmpIndex); } } else { replacePool.Add(unit); } } showPool.Clear(); for (int i = 0; i < newShowPool.Length; i++) { if (newShowPool [i] == null) { SuperListCell unit; if (replacePool.Count > 0) { unit = replacePool [0]; replacePool.RemoveAt(0); } else { unit = hidePool [0]; hidePool.RemoveAt(0); unit.transform.SetParent(container.transform, false); } newShowPool [i] = unit; SetCellIndex(unit, tmpList [i]); SetCellData(unit, tmpList [i]); } showPool.Add(newShowPool [i]); } foreach (SuperListCell unit in replacePool) { unit.transform.SetParent(pool.transform, false); hidePool.Add(unit); } } } else { if (_nowIndex - showIndex == rowNum) { for (int i = 0; i < _nowIndex - showIndex; i++) { int newIndex = showIndex + rowNum * colNum + i; SuperListCell unit = showPool [0]; showPool.RemoveAt(0); if (newIndex < data.Count) { showPool.Add(unit); SetCellIndex(unit, newIndex); SetCellData(unit, newIndex); } else { hidePool.Add(unit); unit.transform.SetParent(pool.transform, false); } } } else if (_nowIndex - showIndex == -rowNum) { for (int i = 0; i < showIndex - _nowIndex; i++) { int newIndex = showIndex - rowNum + i; SuperListCell unit; if (showPool.Count == rowNum * colNum) { unit = showPool [showPool.Count - 1]; showPool.RemoveAt(showPool.Count - 1); } else { unit = hidePool [0]; hidePool.RemoveAt(0); unit.transform.SetParent(container.transform, false); } showPool.Insert(0, unit); SetCellIndex(unit, newIndex); SetCellData(unit, newIndex); } } else { List <int> tmpList = new List <int> (); for (int i = 0; i < rowNum * colNum; i++) { if (_nowIndex + i < data.Count) { tmpList.Add(_nowIndex + i); } else { break; } } SuperListCell[] newShowPool = new SuperListCell[tmpList.Count]; List <SuperListCell> replacePool = new List <SuperListCell> (); for (int i = 0; i < showPool.Count; i++) { SuperListCell unit = showPool [i]; int tmpIndex = unit.index; if (tmpList.Contains(tmpIndex)) { newShowPool [tmpList.IndexOf(tmpIndex)] = unit; if (_dataHasChange) { SetCellData(unit, tmpIndex); } if (_insertHasChange) { SetCellIndex(unit, tmpIndex); } } else { replacePool.Add(unit); } } showPool.Clear(); for (int i = 0; i < newShowPool.Length; i++) { if (newShowPool [i] == null) { SuperListCell unit; if (replacePool.Count > 0) { unit = replacePool [0]; replacePool.RemoveAt(0); } else { unit = hidePool [0]; hidePool.RemoveAt(0); unit.transform.SetParent(container.transform, false); } newShowPool [i] = unit; SetCellIndex(unit, tmpList [i]); SetCellData(unit, tmpList [i]); } showPool.Add(newShowPool [i]); } foreach (SuperListCell unit in replacePool) { unit.transform.SetParent(pool.transform, false); hidePool.Add(unit); } } } showIndex = _nowIndex; }
void CellClick(GameObject obj) { SuperListCell cell = obj.GetComponent <SuperListCell> (); SetSelectedIndex(cell.index); }