//刷新 Cell 的位置 private void RefreshAllCellPos() { //起始点不变的情况, 位置也不需要改变, 直接返回 int tInstaceCellStartDataIndex = mGridArrangeBase.GetNewStartDataIndex(); if (mInstaceCellStartDataIndex == tInstaceCellStartDataIndex) { return; } mInstaceCellStartDataIndex = tInstaceCellStartDataIndex; //新的数据索引表 List <int> tNewDataIndexList = mGridArrangeBase.GetNewDataIndexList(); int tNewI = 0; int tOldI = 0; int i = 0; while (true) { ++i; if (i > 150) { Debug.LogError("cell 刷新位置时,循环次数超出150次, 不合理, 已退出"); return; } //找出新的 数据索引 int tNewDataIndex = -1; for (; tNewI < tNewDataIndexList.Count; ++tNewI) { int tDataIndex = tNewDataIndexList[tNewI]; //新的索引在老的也有, 不用处理 if (mCellDic.ContainsKey(tDataIndex)) { continue; } tNewDataIndex = tDataIndex; break; } //没新的直接返回 if (tNewDataIndex == -1) { break; } //将无用的数据索引替换为新的 for (; tOldI < mDataIndexList.Count; ++tOldI) { int tOldDataIndex = mDataIndexList[tOldI]; //老的索引在新的也有, 不用处理 if (tNewDataIndexList.Contains(tOldDataIndex)) { continue; } mDataIndexList[tOldI] = tNewDataIndex; GameObject tCell = mCellDic[tOldDataIndex]; mCellDic.Remove(tOldDataIndex); mCellDic.Add(tNewDataIndex, tCell); RectTransform tRectTransform = tCell.transform as RectTransform; tRectTransform.anchoredPosition = GetAnchorPosByDataIndex(tNewDataIndex); mConfig.mDisplayCellAction(tNewDataIndex, tCell); break; } } }