public List <Connection> FindPath(Vector3 pos)
        {
            if (pos == transform.position)
            {
                return(null);
            }

            TileNavGraph graph = TileNavGraph.Instance;

            if (graph == null)
            {
                return(null);
            }

            targetNode = graph.GetNode(pos);

            if (targetNode == null || targetNode.Weight == graph.UnreachableCost)
            {
                return(null);
            }

            startNode = graph.GetNode(transform.position);

            ComputePathfinding(targetNode);
            return(path);
        }
Esempio n. 2
0
        public void SearchPath(Vector3 beginPos, Vector3 targetPos, Steering.OnPathFoundHandler onPathFoundEvent)
        {
            TileNavGraph graph = TileNavGraph.Instance;

            origin = graph.GetNode(beginPos);
            target = graph.GetNode(targetPos);

            if (origin == null || target == null)
            {
                return;
            }

            OpenList.Clear();
            ClosedList.Clear();
            Path.Clear();

            onPathFound = onPathFoundEvent;
            PathThread  = new Thread(new ThreadStart(FindPath));
            PathThread.Start();
        }