private void AnalyseEnvironment(int localRangeX, int localRangeY, List <Vector2> platformList) { try { //List<Vector2> platformList = environmentAnalyser.CheckEnvironmet(aiPosition, localRangeX, localRangeY, boxFactor); foreach (MapToAreaPointer mtap in mapCache) { mtap.Type = SquareType.AIR; mtap.RangeToNextAbove = -1; mtap.Area = null; } foreach (Vector2 v in platformList) { int x = DivByBoxFactor(v.x) + offSetX; int y = DivByBoxFactor(v.y) + offSetY; if (x < 0 || y < 0 || x >= mapCache.GetLength(1) || y >= mapCache.GetLength(0)) { continue; } mapCache[y, x] = new MapToAreaPointer(SquareType.UNDEFINDED); } for (int x = 0; x < mapCache.GetLength(1); x++) { for (int y = 0; y < mapCache.GetLength(0); y++) { if (mapCache[y, x].Type == SquareType.UNDEFINDED) { if (y < mapCache.GetLength(0) - charachterHight) { bool isPlatform = true; for (int i = y + 1; i <= y + charachterHight; i++) { if (mapCache[i, x].Type != SquareType.AIR) { isPlatform = false; } } if (isPlatform) { mapCache[y, x].Type = SquareType.PLATFORM; } else { mapCache[y, x].Type = SquareType.BARRIER; } } } } } } catch (System.IndexOutOfRangeException e) { //Debug.Log(e.StackTrace); Debug.LogError(e); } }
private MapToAreaPointer[,] CreateMapCache(int localRangeX, int localRangeY) { MapToAreaPointer[,] toReturn = new MapToAreaPointer[2 * localRangeY + 1, 2 * localRangeX + 1]; for (int x = 0; x < toReturn.GetLength(1); x++) { for (int y = 0; y < toReturn.GetLength(0); y++) { toReturn[y, x] = new MapToAreaPointer(); } } return(toReturn); }