internal void MakeConnection(Doorway a, Doorway b, System.Random randomStream) { bool areDoorwaysFromDifferentDungeons = (a.Dungeon != b.Dungeon); a.Tile.Placement.UnusedDoorways.Remove(a); a.Tile.Placement.UsedDoorways.Add(a); b.Tile.Placement.UnusedDoorways.Remove(b); b.Tile.Placement.UsedDoorways.Add(b); a.ConnectedDoorway = b; b.ConnectedDoorway = a; if (!areDoorwaysFromDifferentDungeons) { var conn = new DoorwayConnection(a, b); connections.Add(conn); } // Add door prefab List <GameObject> doorPrefabs = (a.DoorPrefabs.Count > 0) ? a.DoorPrefabs : b.DoorPrefabs; if (doorPrefabs.Count > 0 && !(a.HasDoorPrefab || b.HasDoorPrefab)) { GameObject doorPrefab = doorPrefabs[randomStream.Next(0, doorPrefabs.Count)]; if (doorPrefab != null) { GameObject door = (GameObject)GameObject.Instantiate(doorPrefab); door.transform.parent = gameObject.transform; door.transform.position = a.transform.position; door.transform.rotation = a.transform.rotation; door.transform.localScale = a.transform.localScale; doors.Add(door); a.SetUsedPrefab(door); b.SetUsedPrefab(door); DungeonUtil.AddAndSetupDoorComponent(this, door, a); } } }
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 MakeConnection(Doorway a, Doorway b, System.Random randomStream) { bool areDoorwaysFromDifferentDungeons = (a.Dungeon != b.Dungeon); a.Tile.Placement.UnusedDoorways.Remove(a); a.Tile.Placement.UsedDoorways.Add(a); b.Tile.Placement.UnusedDoorways.Remove(b); b.Tile.Placement.UsedDoorways.Add(b); a.ConnectedDoorway = b; b.ConnectedDoorway = a; if (!areDoorwaysFromDifferentDungeons) { var conn = new DoorwayConnection(a, b); connections.Add(conn); } // Add door prefab Doorway chosenDoor; // If both doorways have door prefabs.. if (a.DoorPrefabs.Count > 0 && b.DoorPrefabs.Count > 0) { // ..A is selected if its priority is greater than or equal to B.. if (a.DoorPrefabPriority >= b.DoorPrefabPriority) { chosenDoor = a; } // .. otherwise, B is chosen.. else { chosenDoor = b; } } // ..if only one doorway has a prefab, use that one else { chosenDoor = (a.DoorPrefabs.Count > 0) ? a : b; } List <GameObject> doorPrefabs = chosenDoor.DoorPrefabs; if (doorPrefabs.Count > 0 && !(a.HasDoorPrefab || b.HasDoorPrefab)) { GameObject doorPrefab = doorPrefabs[randomStream.Next(0, doorPrefabs.Count)]; if (doorPrefab != null) { GameObject door = (GameObject)GameObject.Instantiate(doorPrefab); door.transform.parent = gameObject.transform; door.transform.position = a.transform.position; door.transform.localScale = a.transform.localScale; if (!chosenDoor.AvoidRotatingDoorPrefab) { door.transform.rotation = a.transform.rotation; } doors.Add(door); a.SetUsedPrefab(door); b.SetUsedPrefab(door); DungeonUtil.AddAndSetupDoorComponent(this, door, a); } } }