/// <summary> /// Places a passage between two cells in a room. /// </summary> /// <param name="cell">Cell</param> /// <param name="neighbour">Neighbour cell</param> /// <param name="direction">Direction</param> protected void CreateLabyrinthPassageInRoom(LabyrinthCell cell, LabyrinthCell neighbour, LabyrinthDirection direction) { // Set passage to neighbour cell LabyrinthEdgePassage p = Instantiate(labyrinthPassage) as LabyrinthEdgePassage; p.InitializeEdge(cell, neighbour, direction); // Set opposite passage p = Instantiate(labyrinthPassage) as LabyrinthEdgePassage; p.InitializeEdge(neighbour, cell, direction.GetOppositeDirection()); // If the to rooms of the neighbouring cells are different, the rooms will be merged. if (cell.Room != neighbour.Room) { LabyrinthRoom absorbedRoom = neighbour.Room; cell.Room.AbsorbRoom(absorbedRoom); // Destroy the unnecessery room instance rooms.Remove(absorbedRoom); DestroyImmediate(absorbedRoom); } }
/// <summary> /// Creates a labyrinth wall with the given parameters. /// </summary> /// <param name="cell">Cell</param> /// <param name="neighbour">Neighbour cell</param> /// <param name="direction">Direction</param> protected void CreateLabyrinthWall(LabyrinthCell cell, LabyrinthCell neighbour, LabyrinthDirection direction) { // Wall to the neighbour LabyrinthEdgeWall wall = Instantiate(labyrinthWall) as LabyrinthEdgeWall; wall.InitializeEdge(cell, neighbour, direction); // If the neighbour is not on the edge of the labyrinth, set a wall on the opposite side of the neighbour cell. if (neighbour != null) { wall = Instantiate(labyrinthWall) as LabyrinthEdgeWall; wall.InitializeEdge(neighbour, cell, direction.GetOppositeDirection()); } }
/// <summary> /// Creates a labyrinth passage with the given parameters. /// </summary> /// <param name="cell">Cell</param> /// <param name="neighbour">Neighbour cell</param> /// <param name="direction">Direction</param> protected void CreateLabyrinthPassage(LabyrinthCell cell, LabyrinthCell neighbour, LabyrinthDirection direction) { // Choose between a passage or a door LabyrinthEdgePassage p; if (Random.value < doorSpawnProbability) p = labyrinthDoor; else p = labyrinthPassage; // Passage from the cell to it's neighbour LabyrinthEdgePassage passage = Instantiate(p) as LabyrinthEdgePassage; passage.InitializeEdge(cell, neighbour, direction); // Passage from the neighbour to the cell passage = Instantiate(p) as LabyrinthEdgePassage; // Check if a door has been placed and assign the cell after the door a new room. if (passage is LabyrinthEdgeDoor) neighbour.InitializeCell(CreateLabyrinthRoom(cell.Room.RoomIndex)); else neighbour.InitializeCell(cell.Room); passage.InitializeEdge(neighbour, cell, direction.GetOppositeDirection()); }