public void FloodFill() { if (astar.astarData.graphs == null) { return; } uint area = 0; lastUniqueAreaIndex = 0; if (floodStack == null) { floodStack = new Stack <GraphNode> (1024); } Stack <GraphNode> stack = floodStack; var graphs = astar.graphs; // Iterate through all nodes in all graphs // and reset their Area field for (int i = 0; i < graphs.Length; i++) { NavGraph graph = graphs[i]; if (graph != null) { graph.GetNodes(node => { node.Area = 0; return(true); }); } } int smallAreasDetected = 0; bool warnAboutAreas = false; List <GraphNode> smallAreaList = Pathfinding.Util.ListPool <GraphNode> .Claim(); for (int i = 0; i < graphs.Length; i++) { NavGraph graph = graphs[i]; if (graph == null) { continue; } GraphNodeDelegateCancelable del = delegate(GraphNode node) { if (node.Walkable && node.Area == 0) { area++; uint thisArea = area; if (area > GraphNode.MaxAreaIndex) { if (smallAreaList.Count > 0) { GraphNode smallOne = smallAreaList[smallAreaList.Count - 1]; thisArea = smallOne.Area; smallAreaList.RemoveAt(smallAreaList.Count - 1); //Flood fill the area again with area ID GraphNode.MaxAreaIndex-1, this identifies a small area stack.Clear(); stack.Push(smallOne); smallOne.Area = GraphNode.MaxAreaIndex; while (stack.Count > 0) { stack.Pop().FloodFill(stack, GraphNode.MaxAreaIndex); } smallAreasDetected++; } else { // Forced to consider this a small area area--; thisArea = area; warnAboutAreas = true; } } stack.Clear(); stack.Push(node); int counter = 1; node.Area = thisArea; while (stack.Count > 0) { counter++; stack.Pop().FloodFill(stack, thisArea); } if (counter < astar.minAreaSize) { smallAreaList.Add(node); } } return(true); }; graph.GetNodes(del); } lastUniqueAreaIndex = area; if (warnAboutAreas) { Debug.LogError("Too many areas - The maximum number of areas is " + GraphNode.MaxAreaIndex + ". Try raising the A* Inspector -> Settings -> Min Area Size value. Enable the optimization ASTAR_MORE_AREAS under the Optimizations tab."); } if (smallAreasDetected > 0) { astar.Log(smallAreasDetected + " small areas were detected (fewer than " + astar.minAreaSize + " nodes)," + "these might have the same IDs as other areas, but it shouldn't affect pathfinding in any significant way (you might get All Nodes Searched as a reason for path failure)." + "\nWhich areas are defined as 'small' is controlled by the 'Min Area Size' variable, it can be changed in the A* inspector-->Settings-->Min Area Size" + "\nThe small areas will use the area id " + GraphNode.MaxAreaIndex); } Pathfinding.Util.ListPool <GraphNode> .Release(smallAreaList); }