public void TakeSnapshot(GridBase <PathNode> grid, PathNode current, List <PathNode> openList, List <PathNode> closedList) { GridSnapshotAction gridSnapshotAction = new GridSnapshotAction(); gridSnapshotAction.AddAction(HideNodeVisuals); for (int x = 0; x < grid.Width; x++) { for (int y = 0; y < grid.Height; y++) { PathNode pathNode = grid.GetCell(x, y); int gCost = pathNode.gCost; int hCost = pathNode.hCost; int fCost = pathNode.fCost; Vector3 gridPosition = new Vector3(pathNode.Position.x, pathNode.Position.y) * grid.CellSize + Vector3.one * grid.CellSize * .5f; bool isCurrent = pathNode == current; bool isInOpenList = openList.Contains(pathNode); bool isInClosedList = closedList.Contains(pathNode); int tmpX = x; int tmpY = y; gridSnapshotAction.AddAction(() => { Transform visualNode = visualNodeArray[tmpX, tmpY]; SetupVisualNode(visualNode, gCost, hCost, fCost); Color backgroundColor = UtilsClass.GetColorFromString("636363"); if (isInClosedList) { backgroundColor = new Color(1, 0, 0); } if (isInOpenList) { backgroundColor = UtilsClass.GetColorFromString("009AFF"); } if (isCurrent) { backgroundColor = new Color(0, 1, 0); } var sprite = visualNode.GetComponentInChildren <SpriteRenderer>(); if (sprite != null) { sprite.color = backgroundColor; } }); } } gridSnapshotActionList.Add(gridSnapshotAction); }
void Update() { // Just for tests. Refactor this for best tests if (Input.GetMouseButtonDown(0)) { var mousePos = UtilsClass.GetMouseWorldPosition(); grid.SetCell(mousePos, true); } if (Input.GetMouseButtonDown(1)) { var mousePos = UtilsClass.GetMouseWorldPosition(); Debug.Log(grid.GetCell(mousePos)); } }