public Vector3[] GetSolutionPath(IPathTerrain terrain) { if (!HasSuccessfullyCompleted()) { return(null); } LinkedList <Planning.Node> path = GetSolutionPath(); if (path == null || path.Count == 0) { return(null); } Vector3[] pathPoints = new Vector3[path.Count]; int i = 0; foreach (Planning.Node node in path) { Vector3 nodePos = terrain.GetPathNodePos(node.Index); pathPoints[i] = nodePos; i++; } // Set the first position to be the start position pathPoints[0] = GetStartPos(); // Set the last position to be the goal position. int lastIndex = Mathf.Clamp(i, 0, path.Count - 1); System.Diagnostics.Debug.Assert(lastIndex > 1 && lastIndex < path.Count); pathPoints[lastIndex] = GetGoalPos(); return(pathPoints); }
public Vector3[] GetSolutionPath(IPathTerrain terrain) { if (!HasSuccessfullyCompleted()) { return(null); } // LinkedList<Planning.Node> path = GetSolutionPath(); if (m_solutionNodeList == null || m_solutionNodeList.Count == 0) { return(null); } List <int> PathCornerIndexList = null; if (terrain is PathGrid) { PathCornerIndexList = (terrain as PathGrid).CornerIndexs(m_solutionNodeList.ToArray()); } else { Debug.LogError("terrain is not PathGrid"); } Vector3[] pathPoints = new Vector3[PathCornerIndexList.Count]; int i = 0; foreach (int cornerIndex in PathCornerIndexList) { //Debug.Log("node.Index:" + node.Index); Vector3 nodePos = terrain.GetPathNodePos(cornerIndex); pathPoints[i] = nodePos; i++; } // Set the first position to be the start position pathPoints[0] = GetStartPos(); // Set the last position to be the goal position. int lastIndex = Mathf.Clamp(i, 0, PathCornerIndexList.Count - 1); System.Diagnostics.Debug.Assert(lastIndex > 1 && lastIndex < PathCornerIndexList.Count); pathPoints[lastIndex] = GetGoalPos(); return(pathPoints); }