// Get a snapshot of the final path public void FinalPathSnapshot(NodeGrid <Node> grid, List <Node> path) { GridSnapshotAction gridSnapshotAction = new GridSnapshotAction(); gridSnapshotAction.AddAction(HideVisuals); for (int x = 0; x < grid.GetWidth(); x++) { for (int y = 0; y < grid.GetHeight(); y++) { for (int z = 0; z < grid.GetDepth(); z++) { Node node = grid.GetGridObject(x, y, z); int g = node.g; int h = node.h; int f = node.f; Vector3 gridPos = new Vector3(node.x, node.y, node.z) * grid.GetNodeSize() + Vector3.one * grid.GetNodeSize() * 5f; bool isInPath = path.Contains(node); int tmpX = x; int tmpY = y; int tmpZ = z; gridSnapshotAction.AddAction(() => { Transform visualNode = visualNodeArray[tmpX, tmpY, tmpZ]; SetupVisualNode(visualNode, g, h, f); Material material; if (isInPath) { material = nodeSearching; } else { material = nodeDefault; } visualNode.GetComponent <MeshRenderer>().material = material; }); } } } gridSnapshotActions.Add(gridSnapshotAction); }
// Set up the grid of visual nodes public void Setup(NodeGrid <Node> grid) { // Get grid dimensions visualNodeArray = new Transform[grid.GetWidth(), grid.GetHeight(), grid.GetDepth()]; // Make a visual node at each grid coordinate for (int x = 0; x < grid.GetWidth(); x++) { for (int y = 0; y < grid.GetHeight(); y++) { for (int z = 0; z < grid.GetDepth(); z++) { Vector3 gridPos = new Vector3(x, y, z) * grid.GetNodeSize() + Vector3.one * grid.GetNodeSize() * .5f; Transform visualNode = CreateVisualNode(gridPos); visualNodeArray[x, y, z] = visualNode; visualNodeList.Add(visualNode); } } } HideVisuals(); }