public void generateRange(int originX, int originY, int range, Tile tileType) { range = range * 10; close.Clear(); open.Clear(); open.Add(tiles[originX, originY]); while (open.Capacity > 1) { open = open.OrderBy(g => g.G).ToList(); current = open[0]; if (current.G + 10 < range + 1) { //Debug.Log(current.G); if (current.X - 1 > -1) { if (!tiles[current.X - 1, current.Y].isInClose) { if (tiles[current.X - 1, current.Y].walkable) { if (!tiles[current.X - 1, current.Y].isInOpen || tiles[current.X - 1, current.Y].G > current.G + 10) { tiles[current.X - 1, current.Y].isInOpen = true; tiles[current.X - 1, current.Y].G = current.G + 10; open.Add(tiles[current.X - 1, current.Y]); } } } } if (current.X + 1 < tiles.GetLength(0)) { if (!tiles[current.X + 1, current.Y].isInClose) { if (tiles[current.X + 1, current.Y].walkable) { if (!tiles[current.X + 1, current.Y].isInOpen || tiles[current.X + 1, current.Y].G > current.G + 10) { tiles[current.X + 1, current.Y].isInOpen = true; tiles[current.X + 1, current.Y].G = current.G + 10; open.Add(tiles[current.X + 1, current.Y]); } } } } if (current.Y - 1 > -1 && !tiles[current.X, current.Y - 1].isInClose) { if (!tiles[current.X, current.Y - 1].isInClose) { if (tiles[current.X, current.Y - 1].walkable) { if (!tiles[current.X, current.Y - 1].isInOpen || tiles[current.X, current.Y - 1].G > current.G + 10) { tiles[current.X, current.Y - 1].isInOpen = true; tiles[current.X, current.Y - 1].G = current.G + 10; open.Add(tiles[current.X, current.Y - 1]); } } } } if (current.Y + 1 < tiles.GetLength(1)) { if (!tiles[current.X, current.Y + 1].isInClose) { if (tiles[current.X, current.Y + 1].walkable) { if (!tiles[current.X, current.Y + 1].isInOpen || tiles[current.X, current.Y + 1].G > current.G + 10) { tiles[current.X, current.Y + 1].isInOpen = true; tiles[current.X, current.Y + 1].G = current.G + 10; open.Add(tiles[current.X, current.Y + 1]); } } } } } if (current.G + 15 < range + 1) { //Debug.Log(current.G); if ((current.X - 1 > -1 && current.Y - 1 > -1)) { if (!tiles[current.X - 1, current.Y - 1].isInClose) { if ((tiles[current.X - 1, current.Y - 1].walkable && tiles[current.X - 1, current.Y].walkable) || (tiles[current.X - 1, current.Y - 1].walkable && tiles[current.X, current.Y - 1].walkable)) { if (!tiles[current.X - 1, current.Y - 1].isInOpen || tiles[current.X - 1, current.Y - 1].G > current.G + 15) { tiles[current.X - 1, current.Y - 1].isInOpen = true; tiles[current.X - 1, current.Y - 1].G = current.G + 15; open.Add(tiles[current.X - 1, current.Y - 1]); } } } } if (current.X + 1 < tiles.GetLength(0) && current.Y - 1 > -1) { if (!tiles[current.X + 1, current.Y - 1].isInClose) { if ((tiles[current.X + 1, current.Y - 1].walkable && tiles[current.X + 1, current.Y].walkable) || (tiles[current.X + 1, current.Y - 1].walkable && tiles[current.X, current.Y - 1].walkable)) { if (!tiles[current.X + 1, current.Y - 1].isInOpen || tiles[current.X + 1, current.Y - 1].G > current.G + 15) { tiles[current.X + 1, current.Y - 1].isInOpen = true; tiles[current.X + 1, current.Y - 1].G = current.G + 15; open.Add(tiles[current.X + 1, current.Y - 1]); } } } } if (current.X - 1 > -1 && current.Y + 1 < tiles.GetLength(1)) { if (!tiles[current.X - 1, current.Y + 1].isInClose) { if ((tiles[current.X - 1, current.Y + 1].walkable && tiles[current.X - 1, current.Y].walkable) || (tiles[current.X - 1, current.Y + 1].walkable && tiles[current.X, current.Y + 1].walkable)) { if (!tiles[current.X - 1, current.Y + 1].isInOpen || tiles[current.X - 1, current.Y + 1].G > current.G + 15) { tiles[current.X - 1, current.Y + 1].isInOpen = true; tiles[current.X - 1, current.Y + 1].G = current.G + 15; open.Add(tiles[current.X - 1, current.Y + 1]); } } } } if (current.X + 1 < tiles.GetLength(0) && current.Y + 1 < tiles.GetLength(1)) { if (!tiles[current.X + 1, current.Y + 1].isInClose) { if ((tiles[current.X + 1, current.Y + 1].walkable && tiles[current.X + 1, current.Y].walkable) || (tiles[current.X + 1, current.Y + 1].walkable && tiles[current.X, current.Y + 1].walkable)) { if (!tiles[current.X + 1, current.Y + 1].isInOpen || tiles[current.X + 1, current.Y + 1].G > current.G + 15) { tiles[current.X + 1, current.Y + 1].isInOpen = true; tiles[current.X + 1, current.Y + 1].G = current.G + 15; open.Add(tiles[current.X + 1, current.Y + 1]); } } } } } open.Remove(current); open.TrimExcess(); current.isInClose = true; close.Add(current); //Debug.Log(open.Capacity); } foreach (AStarTile tile in close) { if (tile.G != 0) { mapManager.generateRangeTile(tile.X, tile.Y, tileType); } //Debug.Log("X" + tile.X + "Y" + tile.Y); } }