using System.Collections.Generic; using Gameplay.Level; using UnityEngine; namespace Gameplay.Area.BoardView { public class BoardViewHelper { private static List _cacheCellIndexList = new List(); public static List GenerateBoard(List cellIndexList) { _cacheCellIndexList.Clear(); _cacheCellIndexList.AddRange(cellIndexList); var result = new List(); var tgsSystem = LevelManager.Instance.CurrentLevel.Map.TerrainGridSystem; BoardViewData workViewData = null; List workCellIndexList = new List(); List nextWorkCellIndexList = new List(); while (_cacheCellIndexList.Count > 0) { if (workViewData == null) { workCellIndexList.Clear(); var workCellIndex = _cacheCellIndexList[^1]; _cacheCellIndexList.RemoveAt(_cacheCellIndexList.Count - 1); workViewData = new BoardViewData(); workViewData.cellIndexList.Add(workCellIndex); result.Add(workViewData); workCellIndexList.Add(workCellIndex); } else { nextWorkCellIndexList.Clear(); for (int j = 0; j < workCellIndexList.Count; j++) { var workCellIndex = workCellIndexList[j]; var aroundCell = tgsSystem.CellGetNeighbours(workCellIndex); for (int i = 0; i < aroundCell.Count; i++) { var cell = aroundCell[i]; var findIndex = _cacheCellIndexList.IndexOf(cell.index); if (findIndex == -1) { continue; } workViewData.cellIndexList.Add(cell.index); // fast remove _cacheCellIndexList[findIndex] = _cacheCellIndexList[^1]; _cacheCellIndexList.RemoveAt(_cacheCellIndexList.Count - 1); nextWorkCellIndexList.Add(cell.index); } } if (nextWorkCellIndexList.Count == 0) { workViewData = null; } else { // switch work list workCellIndexList.Clear(); workCellIndexList.AddRange(nextWorkCellIndexList); } } } return result; } } }