public void StartNavigation() { if (m_InitStatus == NavInitStatus.INCOMPLETE) { Debug.Log("Starting Navigation!"); List <MDSNode> allNodes = MainController.Instance.GetNodeController().NodeObjList; Debug.Log("Nodes: " + allNodes.Count); MDSNode closestNode = ReturnClosestNode(allNodes, _referencePoint.position); Debug.Log("Closest node: " + closestNode.gameObject.name); MDSNode targetNode = MainController.Instance.GetNodeController().TargetNode; Debug.Log("Target node: " + targetNode.NodeInfo.name); // Set neighbor nodes for all nodes foreach (MDSNode node in allNodes) { node.FindNeighbors(maxDistance); } // Get path from AStar algorithm path = m_AStar.FindPath(closestNode, targetNode, allNodes); if (path == null) { // Increase search distance for neighbors if none are found maxDistance += .1f; Debug.Log("Increasing search distance to: " + maxDistance); StartNavigation(); return; } // Set next nodes for (int i = 0; i < path.Count - 1; i++) { path[i].NextInList = path[i + 1]; } // Activate the first node path[0].Activate(); m_InitStatus = NavInitStatus.COMPLETED; } }
/// <summary> /// Overloaded NavigateToTarget method that handles re-navigation to a new target using int /// </summary> public void NavigateToTarget(int targetIndex) { MainController.Instance.GetNodeController().SetTargetNode(targetIndex); MainController.Instance.GetNodeController().DeactivateNodes(); try { m_InitStatus = NavInitStatus.INCOMPLETE; StartNavigation(); } catch (System.Exception e) { Debug.LogException(e); } }
/// <summary> /// Method that handles re-navigation to a new target using the target name /// </summary> public void NavigateToTarget(string targetName) { foreach (MDSNode target in MainController.Instance.GetNodeController().TargetNodeObjList) { if (targetName == target.NodeInfo.name) { MainController.Instance.GetNodeController().TargetNode = target; } } try { m_InitStatus = NavInitStatus.INCOMPLETE; StartNavigation(); } catch (System.Exception e) { Debug.LogException(e); } }