Beispiel #1
0
        public void FindPath(Index start, Index end, DiagonalMode diagonal, BaseTraversal2D traversal2D, PathRequestDelegate callback)
        {
            if (!IsValid(start) || !IsValid(end))
            {
                return;
            }
            searchGrid.maxPathLength = maxPathLength;
            bool useThreading = allowThreading;

            if (useThreading == true)
            {
                AsyncPathRequest request = new AsyncPathRequest(searchGrid, start, end, diagonal, traversal2D, (Path path, PathRequestStatus status) =>
                {
                    PathView.setRenderPath(this, path);
                    callback(path, status);
                });
                ThreadManager.Active.asyncRequest(request);
            }
            else
            {
                PathRequestStatus status;
                Path result = FindPathImmediate(start, end, out status, diagonal);
                PathView.setRenderPath(this, result);
                callback(result, status);
            }

            Path FindPathImmediate(Index subStart, Index subEnd, out PathRequestStatus subStatus, DiagonalMode subDiagonal)
            {
                searchGrid.maxPathLength = maxPathLength;
                Path path = null;
                PathRequestStatus temp = PathRequestStatus.InvalidIndex;

                searchGrid.FindPath(subStart, subEnd, subDiagonal, traversal2D, (Path result, PathRequestStatus resultStatus) =>
                {
                    temp = resultStatus;
                    if (resultStatus == PathRequestStatus.PathFound)
                    {
                        path = result;
                        PathView.setRenderPath(this, path);
                    }
                });

                subStatus = temp;
                return(path);
            }
        }
Beispiel #2
0
        public static void setRenderPath(AStarGrid grid, Path path)
        {
            if (!Application.isEditor)
            {
                return;
            }
            // Make sure the path is valid
            if (path == null)
            {
                return;
            }

            // Find the component
            PathView view = findViewForGrid(grid);

            // Check for error
            if (view == null)
            {
                return;
            }

            // Udpate the render path
            view.setRenderPath(path);
        }