Пример #1
0
    public void AddWorkItem(AstarWorkItem item)
    {
        workItems.AddWorkItem(item);

        if (!workItemLock.Held)
        {
            workItemLock = PausePathfindingSoon();
        }

#if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            FlushWorkItems();
        }
#endif
    }
Пример #2
0
    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;
    }
Пример #3
0
 public void FlushWorkItems(bool unblockOnComplete, bool block)
 {
     PathProcessor.GraphUpdateLock graphUpdateLock = this.PausePathfinding();
     this.PerformBlockingActions(block);
     graphUpdateLock.Release();
 }
Пример #4
0
 public void FlushWorkItems()
 {
     PathProcessor.GraphUpdateLock graphUpdateLock = this.PausePathfinding();
     this.PerformBlockingActions(true);
     graphUpdateLock.Release();
 }