public IEnumerable <Progress> ScanAsync(NavGraph[] graphsToScan = null) { if (graphsToScan == null) { graphsToScan = this.graphs; } if (graphsToScan == null) { yield break; } if (this.isScanning) { throw new InvalidOperationException("Another async scan is already running"); } this.isScanning = true; this.VerifyIntegrity(); PathProcessor.GraphUpdateLock graphUpdateLock = this.PausePathfinding(); this.pathReturnQueue.ReturnPaths(false); if (!Application.isPlaying) { this.data.FindGraphTypes(); GraphModifier.FindAllModifiers(); } yield return(new Progress(0.05f, "Pre processing graphs")); if (AstarPath.OnPreScan != null) { AstarPath.OnPreScan(this); } GraphModifier.TriggerEvent(GraphModifier.EventType.PreScan); this.data.LockGraphStructure(false); Stopwatch watch = Stopwatch.StartNew(); for (int j = 0; j < graphsToScan.Length; j++) { if (graphsToScan[j] != null) { graphsToScan[j].DestroyAllNodesInternal(); } } int num; for (int i = 0; i < graphsToScan.Length; i = num + 1) { if (graphsToScan[i] != null) { float minp = Mathf.Lerp(0.1f, 0.8f, (float)i / (float)graphsToScan.Length); float maxp = Mathf.Lerp(0.1f, 0.8f, ((float)i + 0.95f) / (float)graphsToScan.Length); string progressDescriptionPrefix = string.Concat(new object[] { "Scanning graph ", i + 1, " of ", graphsToScan.Length, " - " }); IEnumerator <Progress> coroutine = this.ScanGraph(graphsToScan[i]).GetEnumerator(); for (;;) { try { if (!coroutine.MoveNext()) { break; } } catch { this.isScanning = false; this.data.UnlockGraphStructure(); graphUpdateLock.Release(); throw; } yield return(new Progress(Mathf.Lerp(minp, maxp, coroutine.Current.progress), progressDescriptionPrefix + coroutine.Current.description)); } progressDescriptionPrefix = null; coroutine = null; } num = i; } this.data.UnlockGraphStructure(); yield return(new Progress(0.8f, "Post processing graphs")); if (AstarPath.OnPostScan != null) { AstarPath.OnPostScan(this); } GraphModifier.TriggerEvent(GraphModifier.EventType.PostScan); this.FlushWorkItems(); yield return(new Progress(0.9f, "Computing areas")); this.FloodFill(); yield return(new Progress(0.95f, "Late post processing")); this.isScanning = false; if (AstarPath.OnLatePostScan != null) { AstarPath.OnLatePostScan(this); } GraphModifier.TriggerEvent(GraphModifier.EventType.LatePostScan); this.euclideanEmbedding.dirty = true; this.euclideanEmbedding.RecalculatePivots(); this.FlushWorkItems(); graphUpdateLock.Release(); watch.Stop(); this.lastScanTime = (float)watch.Elapsed.TotalSeconds; GC.Collect(); this.Log("Scanning - Process took " + (this.lastScanTime * 1000f).ToString("0") + " ms to complete"); yield break; yield break; }
public IEnumerable <Progress> ScanAsync() { if (this.graphs == null) { yield break; } this.isScanning = true; this.euclideanEmbedding.dirty = false; this.VerifyIntegrity(); this.BlockUntilPathQueueBlocked(); this.pathReturnQueue.ReturnPaths(false); this.BlockUntilPathQueueBlocked(); if (!Application.isPlaying) { GraphModifier.FindAllModifiers(); RelevantGraphSurface.FindAllGraphSurfaces(); } RelevantGraphSurface.UpdateAllPositions(); this.astarData.UpdateShortcuts(); yield return(new Progress(0.05f, "Pre processing graphs")); if (AstarPath.OnPreScan != null) { AstarPath.OnPreScan(this); } GraphModifier.TriggerEvent(GraphModifier.EventType.PreScan); Stopwatch watch = Stopwatch.StartNew(); for (int j = 0; j < this.graphs.Length; j++) { if (this.graphs[j] != null) { this.graphs[j].GetNodes(delegate(GraphNode node) { node.Destroy(); return(true); }); } } for (int i = 0; i < this.graphs.Length; i++) { if (this.graphs[i] != null) { float minp = Mathf.Lerp(0.1f, 0.8f, (float)i / (float)this.graphs.Length); float maxp = Mathf.Lerp(0.1f, 0.8f, ((float)i + 0.95f) / (float)this.graphs.Length); string progressDescriptionPrefix = string.Concat(new object[] { "Scanning graph ", i + 1, " of ", this.graphs.Length, " - " }); foreach (Progress progress in this.ScanGraph(this.graphs[i])) { yield return(new Progress(Mathf.Lerp(minp, maxp, progress.progress), progressDescriptionPrefix + progress.description)); } } } yield return(new Progress(0.8f, "Post processing graphs")); if (AstarPath.OnPostScan != null) { AstarPath.OnPostScan(this); } GraphModifier.TriggerEvent(GraphModifier.EventType.PostScan); try { this.FlushWorkItemsInternal(false); } catch (Exception exception) { UnityEngine.Debug.LogException(exception); } yield return(new Progress(0.9f, "Computing areas")); this.FloodFill(); this.VerifyIntegrity(); yield return(new Progress(0.95f, "Late post processing")); this.isScanning = false; if (AstarPath.OnLatePostScan != null) { AstarPath.OnLatePostScan(this); } GraphModifier.TriggerEvent(GraphModifier.EventType.LatePostScan); this.euclideanEmbedding.dirty = true; this.euclideanEmbedding.RecalculatePivots(); this.PerformBlockingActions(true, true); watch.Stop(); this.lastScanTime = (float)watch.Elapsed.TotalSeconds; GC.Collect(); this.Log("Scanning - Process took " + (this.lastScanTime * 1000f).ToString("0") + " ms to complete"); yield break; }