//Post process the grid public void ProcessGrid(BuildGraph builder) { //Make a list of nodes to flag as unwalkable //we can't immediately update them or the //whole thing would go horribly wrong as it //scanned its own output! var unwalkable = new List <BuildGraph.GridPosition>(); //Run through the grid for (var x = 0; x < builder.width; x++) { for (var y = 0; y < builder.height; y++) { //Get a current position var currentPosition = new BuildGraph.GridPosition { x = x, y = y }; //Get all of the neighbours within 2 grid units and see if any //of them are not walkable if (builder.GetNeighbours(currentPosition, 2).Select(cell => builder.GetCell(cell)).Any(gc => !gc.walkable)) { //If so add this cell to the unwalkable //list unwalkable.Add(currentPosition); } } } //Update the map foreach (var unwalk in unwalkable) { builder.GetCell(unwalk).walkable = false; } }
//Post process the grid public void ProcessGrid(BuildGraph builder) { //Make a list of nodes to flag as unwalkable //we can't immediately update them or the //whole thing would go horribly wrong as it //scanned its own output! var unwalkable = new List<BuildGraph.GridPosition>(); //Run through the grid for(var x = 0; x < builder.width; x ++) { for(var y = 0; y < builder.height; y++) { //Get a current position var currentPosition = new BuildGraph.GridPosition { x = x, y = y }; //Get all of the neighbours within 2 grid units and see if any //of them are not walkable if(builder.GetNeighbours(currentPosition, 2).Select(cell=>builder.GetCell(cell)).Any(gc=>!gc.walkable)) { //If so add this cell to the unwalkable //list unwalkable.Add(currentPosition); } } } //Update the map foreach(var unwalk in unwalkable) { builder.GetCell(unwalk).walkable = false; } }
public void ProcessGrid(BuildGraph builder) { var grid = builder.cells.Get<PinchPointGrid>(); var points = new List<PinchInfo>(); grid.cells = new int[builder.width, builder.height]; foreach(var cell in builder.allWalkableCells) { grid.cells[cell.x, cell.y] = builder.GetNeighbours(cell, 10).Count(c=>!builder.GetCell(c).walkable); points.Add(new PinchInfo { pinch = grid.cells[cell.x, cell.y], position = cell }); } grid.pinchPoints = points.OrderByDescending(p => p.pinch).GroupBy(p=>Mathf.FloorToInt(p.position.x/20) + Mathf.FloorToInt(p.position.y/20)*2000).Select(grp=>grp.First()).Select(p => p.position).Take(20).ToList(); }
public void ProcessGrid(BuildGraph builder) { var grid = builder.cells.Get <PinchPointGrid>(); var points = new List <PinchInfo>(); grid.cells = new int[builder.width, builder.height]; foreach (var cell in builder.allWalkableCells) { grid.cells[cell.x, cell.y] = builder.GetNeighbours(cell, 10).Count(c => !builder.GetCell(c).walkable); points.Add(new PinchInfo { pinch = grid.cells[cell.x, cell.y], position = cell }); } grid.pinchPoints = points.OrderByDescending(p => p.pinch).GroupBy(p => Mathf.FloorToInt(p.position.x / 20) + Mathf.FloorToInt(p.position.y / 20) * 2000).Select(grp => grp.First()).Select(p => p.position).Take(20).ToList(); }