internal void PostGenerateDungeon(DungeonGenerator dungeonGenerator) { ConnectionGraph = new DungeonGraph(this); Bounds = UnityUtil.CombineBounds(allTiles.Select(x => x.Placement.Bounds).ToArray()); }
public void FromProxy(DungeonProxy proxyDungeon, DungeonGenerator generator) { Clear(); var proxyToTileMap = new Dictionary <TileProxy, Tile>(); foreach (var tileProxy in proxyDungeon.AllTiles) { // Instantiate & re-position tile var tileObj = GameObject.Instantiate(tileProxy.Prefab, generator.Root.transform); tileObj.transform.localPosition = tileProxy.Placement.Position; tileObj.transform.localRotation = tileProxy.Placement.Rotation; // Add tile to lists var tile = tileObj.GetComponent <Tile>(); tile.Dungeon = this; tile.Placement = new TilePlacementData(tileProxy.Placement); proxyToTileMap[tileProxy] = tile; allTiles.Add(tile); if (tile.Placement.IsOnMainPath) { mainPathTiles.Add(tile); } else { branchPathTiles.Add(tile); } // Place trigger volume if (generator.PlaceTileTriggers) { tile.AddTriggerVolume(); tile.gameObject.layer = generator.TileTriggerLayer; } // Process doorways var allDoorways = tileObj.GetComponentsInChildren <Doorway>(); foreach (var doorway in allDoorways) { doorway.Tile = tile; doorway.placedByGenerator = true; doorway.HideConditionalObjects = false; tile.AllDoorways.Add(doorway); } foreach (var doorwayProxy in tileProxy.UsedDoorways) { var doorway = allDoorways[doorwayProxy.Index]; tile.UsedDoorways.Add(doorway); foreach (var obj in doorway.BlockerSceneObjects) { if (obj != null) { DestroyImmediate(obj, false); } } } foreach (var doorwayProxy in tileProxy.UnusedDoorways) { var doorway = allDoorways[doorwayProxy.Index]; tile.UnusedDoorways.Add(doorway); foreach (var obj in doorway.ConnectorSceneObjects) { if (obj != null) { DestroyImmediate(obj, false); } } // If there is at least one blocker prefab, select one and spawn it as a child of the doorway if (doorway.BlockerPrefabWeights.HasAnyViableEntries()) { GameObject blocker = GameObject.Instantiate(doorway.BlockerPrefabWeights.GetRandom(generator.RandomStream)) as GameObject; blocker.transform.parent = doorway.gameObject.transform; blocker.transform.localPosition = Vector3.zero; blocker.transform.localScale = Vector3.one; if (!doorway.AvoidRotatingBlockerPrefab) { blocker.transform.localRotation = Quaternion.identity; } } } } // Add doorway connections foreach (var proxyConn in proxyDungeon.Connections) { var tileA = proxyToTileMap[proxyConn.A.TileProxy]; var tileB = proxyToTileMap[proxyConn.B.TileProxy]; var doorA = tileA.AllDoorways[proxyConn.A.Index]; var doorB = tileB.AllDoorways[proxyConn.B.Index]; doorA.ConnectedDoorway = doorB; doorB.ConnectedDoorway = doorA; var conn = new DoorwayConnection(doorA, doorB); connections.Add(conn); SpawnDoorPrefab(doorA, doorB, generator.RandomStream); } }
internal void PreGenerateDungeon(DungeonGenerator dungeonGenerator) { DungeonFlow = dungeonGenerator.DungeonFlow; }
internal void PostGenerateDungeon(DungeonGenerator dungeonGenerator) { ConnectionGraph = new DungeonGraph(this); }