Ejemplo n.º 1
0
        public static void SearchPathRequest(Pathfinding requester, Vector2 startPos, Vector2 endPos)
        {
            Node start = PathfindingGrid.Instance.ClosestNodeFromWorldPoint(startPos);
            Node end   = PathfindingGrid.Instance.ClosestNodeFromWorldPoint(endPos);

            if (PathfindingGrid.Instance.useThreading)
            {
                PathRequest request = new PathRequest(requester, start, end);
                pathRequests.Add(request);
            }
            else
            {
                Vector2[] newPath = AStar.FindPath(start, end);
                requester.OnPathFound(newPath);
            }
        }
Ejemplo n.º 2
0
        void Update()
        {
            while (functionsToRunInMainThread.Count > 0)
            {
                Action function = functionsToRunInMainThread[0];
                functionsToRunInMainThread.RemoveAt(0);
                function();
            }

            while (pathRequests.Count > 0 && readyToTakeNewPath)
            {
                readyToTakeNewPath = false;
                PathRequest requester = pathRequests[0];
                pathRequests.RemoveAt(0);
                IEnumerator pathCount = CountPath(requester.requester, requester.startPosition, requester.endPosition);
                StartCoroutine(pathCount);
            }
        }