Exemplo n.º 1
0
        public void Run()
        {
            if (m_Graph == null)
            {
                Debug.LogError("The assigned graph is either not assigned or invalid.");
                return;
            }

            // Clear state of previous run
            m_Path.Clear();
            m_Graph.Clear();

            // Convert start and end locations to nodes in the graph
            var start = m_Graph.GetClosestNodeToPoint(m_Start);
            var goal  = m_Graph.GetClosestNodeToPoint(m_End);

            if (start == goal)
            {
                Debug.LogError("Start and goal are the same node. No path was found.");
                return;
            }

            // Create a dictionairy to keep track of how we
            // discovered a node.
            var cameFrom = new Dictionary <Node, Node>();

            // Execute the algorithm we have selected.
            AStarSearch.Execute(m_Graph, start, goal, cameFrom);


            // Reconstruct Path
            ReconstructPath(cameFrom, start, goal, m_Path);
        }
Exemplo n.º 2
0
        public void Run()
        {
            if (m_Graph == null)
            {
                Debug.LogError("The assigned graph is either not assigned or invalid.");
                return;
            }

            // Clear state of previous run
            m_Path.Clear();
            m_Graph.Clear();

            // Convert start and end locations to nodes in the graph
            var start = m_Graph.GetClosestNodeToPoint(m_Start);
            var goal  = m_Graph.GetClosestNodeToPoint(m_End);

            if (start == goal)
            {
                Debug.LogError("Start and goal are the same node. No path was found.");
                return;
            }

            // Create a dictionairy to keep track of how we
            // discovered a node.
            var cameFrom = new Dictionary <Node, Node>();

            // Execute the algorithm we have selected.
            AStarSearch.Execute(m_Graph, start, goal, cameFrom);


            // Reconstruct Path
            ReconstructPath(cameFrom, start, goal, m_Path);

            // add path to cyclic path
            var cpScript = GameObject.Find("Path").GetComponent <CyclicPath>();

            //set number of checkpoints
            cpScript.numOfPoints = m_Path.Count;
            //cpScript.controlPoints = m_Path;
            var numOfCps = cpScript.numOfPoints;

            for (int i = 0; i < numOfCps; i++)
            {
                cpScript.controlPoints[i].position = m_Path[i];
            }
        }
Exemplo n.º 3
0
        public List <Vector3> GetPath()
        {
            // Clear state of previous run
            m_Path.Clear();
            m_Graph.Clear();

            // Convert start and end locations to nodes in the graph
            var start = m_Graph.GetClosestNodeToPoint(m_Start);
            var goal  = m_Graph.GetClosestNodeToPoint(m_End);


            // Create a dictionairy to keep track of how we
            // discovered a node.
            var cameFrom = new Dictionary <Node, Node>();

            // Execute the algorithm we have selected.
            AStarSearch.Execute(m_Graph, start, goal, cameFrom);


            // Reconstruct Path
            ReconstructPath(cameFrom, start, goal, m_Path);
            return(this.m_Path);
        }