using System.Collections.Generic; using Gameplay.Level; namespace Gameplay.Area.Around { public static class AroundHelper { private static List _cacheWorkList = new List(); private static List _cacheNextWorkList = new List(); private static List _cacheVisitList = new List(); private static List _cacheCellList = new List(); public static void GetAround(int centerIndex, int stepCount, List result) { var workStep = 0; _cacheWorkList.Clear(); _cacheVisitList.Clear(); _cacheCellList.Clear(); _cacheWorkList.Add(centerIndex); _cacheVisitList.Add(centerIndex); var mapTgs = LevelManager.Instance.CurrentLevel.Map.TerrainGridSystem; while (true) { _cacheNextWorkList.Clear(); for (var i = 0; i < _cacheWorkList.Count; ++i) { var index = _cacheWorkList[i]; mapTgs.CellGetNeighbours(index, _cacheCellList); for (int j = 0; j < _cacheCellList.Count; j++) { var cell = _cacheCellList[j]; if (_cacheVisitList.Contains(cell.index)) { continue; } result.Add(cell.index); _cacheNextWorkList.Add(cell.index); _cacheVisitList.Add(cell.index); } } workStep++; if (workStep >= stepCount) { break; } _cacheWorkList.Clear(); _cacheWorkList.AddRange(_cacheNextWorkList); } } } }