示例#1
0
        /// <summary>
        /// Attempts to find a <see cref="Path"/> between the start and end points and returns the result on completion.
        /// </summary>
        /// <param name="start">The <see cref="Index"/> into the search space representing the start position</param>
        /// <param name="end">The <see cref="Index"/> into the search space representing the end position</param>
        /// <param name="status">The <see cref="PathRequestStatus"/> describing the state of the result</param>
        /// <param name="diagonal">The diagonal mode used when finding a path</param>
        /// <returns>The <see cref="Path"/> that was found or null if the algorithm failed</returns>
        public Path findPathImmediate(Index start, Index end, out PathRequestStatus status, DiagonalMode diagonal)
        {
            // Make sure the grid is ready
            if (verifyReady() == false)
            {
                status = PathRequestStatus.GridNotReady;
                return(null);
            }

            // Update max path length
            searchGrid.maxPathLength = maxPathLength;

            // Store a temp path
            Path path = null;
            PathRequestStatus temp = PathRequestStatus.InvalidIndex;

            // Find a path
            searchGrid.findPath(start, end, diagonal, (Path result, PathRequestStatus resultStatus) =>
            {
                // Store the status
                temp = resultStatus;

                // Make sure the path was found
                if (resultStatus == PathRequestStatus.PathFound)
                {
                    path = result;

#if UNITY_EDITOR
                    PathView.setRenderPath(this, path);
#endif
                }
            });

            status = temp;
            return(path);
        }