Пример #1
0
        // Публичные методы
        public static List <Node> FindPath(NavigationGraph navigationGraph,
                                           NavigationAgent navigationAgent,
                                           NavigationNode destination)
        {
            Node temporaryPathOriginNode = navigationGraph.Graph.AddNode(navigationAgent.transform.position);

            Arc temporaryBackArc = navigationGraph.Graph.AddArc(temporaryPathOriginNode,
                                                                navigationAgent.RareNode,
                                                                Directedness.Undirected);

            Arc temporaryForwardArc = navigationGraph.Graph.AddArc(temporaryPathOriginNode,
                                                                   navigationAgent.FrontNode,
                                                                   Directedness.Undirected);

            IPath path = FindGraphPath(navigationGraph, navigationAgent, destination);

            List <Node> pathAsNodeList = PathToNodeList(path);

            DeleteTemporaryNodeAndArcs(navigationGraph,
                                       temporaryPathOriginNode,
                                       temporaryForwardArc,
                                       temporaryBackArc);

            return(pathAsNodeList);
        }
Пример #2
0
 private static void DeleteTemporaryNodeAndArcs(NavigationGraph navigationGraph,
                                                Node originNode,
                                                Arc forwardArc,
                                                Arc backArk)
 {
     navigationGraph.Graph.DeleteArc(backArk);
     navigationGraph.Graph.DeleteArc(forwardArc);
     navigationGraph.Graph.DeleteNode(originNode);
 }
Пример #3
0
        // Приватные методы
        private static IPath FindGraphPath(NavigationGraph navigationGraph,
                                           NavigationAgent navigationAgent,
                                           NavigationNode destination)
        {
            IPath pathBack = navigationGraph.Graph.FindPath(navigationAgent.RareNode,
                                                            destination.Node,
                                                            Dfs.Direction.Undirected);

            IPath pathForward = navigationGraph.Graph.FindPath(navigationAgent.FrontNode,
                                                               destination.Node,
                                                               Dfs.Direction.Undirected);

            IPath shortestPath = pathBack.NodeCount() > pathForward.NodeCount() ? pathForward : pathBack;

            return(shortestPath);
        }