Example #1
0
 IEnumerator updateAsyncCo()
 {
     updating = true;
     foreach (var a in path.ScanAsync(path.data.graphs))
     {
         yield return(null);
     }
     updating = false;
 }
        public override void Generate(Dungeon dungeon)
        {
            progress.Percentage = 0.0f;

            // Cleanup from last time
            foreach (var door in previousDungeonDoors)
            {
                door.OnDoorStateChanged -= OnDoorStateChanged;
            }

            previousDungeonDoors.Clear();

            // Try to find a pathfinder in the scene if one wasn't supplied
            if (PathFinder == null)
            {
                PathFinder = Component.FindObjectOfType <AstarPath>();

                if (PathFinder == null)
                {
                    Debug.LogError("DunGen can't find an A* Pathfinder script in the scene. Aborting NavMesh generation");
                    return;
                }
            }

            // Snap the bounds of any useable graph to the full bounds of the dungeon
            foreach (var graph in PathFinder.graphs)
            {
                var recast = graph as RecastGraph;

                if (recast != null)
                {
                    recast.forcedBoundsCenter = dungeon.Bounds.center;
                    recast.forcedBoundsSize   = dungeon.Bounds.size;
                }
            }

            // Rescan all graphs
#if ASTAR_PATHFINDING_VERSION_3
            PathFinder.ScanLoop(ProgressCallback);
#else
            foreach (var graph in PathFinder.graphs)
            {
                foreach (var progress in PathFinder.ScanAsync(graph))
                {
                    ProgressCallback(progress);
                }
            }
#endif

            AddDoorOpenListeners();
        }