internal void FindPath(Vector3 start, Vector3 end) { if (mGraph != null && !mbAwaitingPath) { mbAwaitingPath = mGraph.FindPath(start, end, OnPathNotify, mZone.FindWorldNodeLandedIn); mST.ModifyStringText(mFonts[0], "Path Find returned failure immediately!", "PathStatus"); } }
void Update() { // Watch for path request if (Input.GetMouseButton(0)) { int startX, startY, endX, endY; List <PathNode> newMovePath; Vector3 mouseWorldPosition = Utils.GetMouseWorldPosition(); if (isMoving) // start pathfinding from next node { startX = movePath[1].x; startY = movePath[1].y; } else // start from current position { pathGraph.pathGrid.GetXY(transform.position, out startX, out startY); } pathGraph.pathGrid.GetXY(mouseWorldPosition, out endX, out endY); newMovePath = pathGraph.FindPath(startX, startY, endX, endY); if (newMovePath != null) { if (isMoving) //finish current node transition { PathNode lastNode = movePath[0]; movePath = newMovePath; movePath.Insert(0, lastNode); } else { movePath = newMovePath; } movePoint.position = pathGraph.pathGrid.GetCellCenter(mouseWorldPosition); } } // If path is valid if (movePath != null && movePath.Count > 1) { MoveToNextPos(); } else { isMoving = false; } }
public void FindPathTest() { SquarePolygon pointToGo = ((11, 5), 2); SquarePolygon wall1 = ((19, 8), 4); SquarePolygon wall2 = ((11, 19), 4); SquarePolygon wall3 = ((23, 17), 4); var graph = new PathGraph(30, 30); graph.AddWalls(wall1, wall2, wall3); graph.FindPath(pointToGo); Debug.WriteLine(graph.ToPath()); }