/// <summary> /// Initializes the Edge cell. /// </summary> /// <param name="cell">The cell itself</param> /// <param name="neighbour">The neighbour of the cell</param> /// <param name="direction">The direction from the cell to its neighbour</param> public void InitializeEdge(LabyrinthCell cell, LabyrinthCell neighbour, LabyrinthDirection direction) { this.Cell = cell; this.NeighbourCell = neighbour; this.Direction = direction; // Set the edge of the cell. cell.SetCellEdge(direction, this); // Set the cell as parent transform.parent = cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = direction.GetRotation(); }
/// <summary> /// Gets the edge of the given direction. /// </summary> /// <param name="direction">Direction</param> /// <returns>Edge</returns> public LabyrinthCellEdge GetCellEdge(LabyrinthDirection direction) { return cellEdges[(int)direction]; }
/// <summary> /// Sets the edge based on the given direction. /// </summary> /// <param name="direction">Direction</param> /// <param name="edge">Edge</param> public void SetCellEdge(LabyrinthDirection direction, LabyrinthCellEdge edge) { cellEdges[(int)direction] = edge; edgesInUse++; }
/// <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> /// 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 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()); }