/// <summary> /// Attempts to search this grid for a path between the start and end points. /// </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="diagonal">The diagonal mode used when finding paths</param> /// <param name="callback">The <see cref="PathRequestDelegate"/> method to call whe the algorithm has completed</param> public void findPath(Index start, Index end, DiagonalMode diagonal, PathRequestDelegate callback) { // Make sure the grid is ready if (verifyReady() == false) { callback(null, PathRequestStatus.GridNotReady); return; } // Update max path length searchGrid.maxPathLength = maxPathLength; // Get the threading value bool useThreading = allowThreading; #if UNITY_WEBGL // Threading is not allowed on web gl platform useThreading = false; #endif // Check if threading is enabled if (useThreading == true) { // Create a request AsyncPathRequest request = new AsyncPathRequest(searchGrid, start, end, diagonal, (Path path, PathRequestStatus status) => { #if UNITY_EDITOR // Pass the path for rendering before it is used by the caller otherwise nodes may be removed from the path PathView.setRenderPath(this, path); #endif // Invoke callback callback(path, status); }); // Dispatch the request ThreadManager.Active.asyncRequest(request); } else { PathRequestStatus status; // Run the task immediatley Path result = findPathImmediate(start, end, out status, diagonal); #if UNITY_EDITOR // Pass the path for rendering before it is used by the caller otherwise nodes may be removed PathView.setRenderPath(this, result); #endif // Trigger callback callback(result, status); } }
// Constructor public AsyncPathResult(AsyncPathRequest request, Path result, PathRequestStatus status) { this.request = request; this.result = result; this.status = status; }