private void DisableWallpiece(Vector2 overlapPosition, Room thisRoom, Room otherRoom) // thisRoom = new room --|-- otherRoom = room adjacent to the new room { List <WallPiece> overlappingWallPiecesThisRoom = GetWallpiecesByActiveBuildingTile(overlapPosition, thisRoom); List <WallPiece> overlappingWallPiecesOtherRoom = GetWallpiecesByActiveBuildingTile(overlapPosition, otherRoom); for (int i = 0; i < overlappingWallPiecesThisRoom.Count; i++) { WallPiece overlappingWallPieceThisRoom = overlappingWallPiecesThisRoom[i]; for (int j = 0; j < overlappingWallPiecesOtherRoom.Count; j++) { WallPiece overlappingWallPieceOtherRoom = overlappingWallPiecesOtherRoom[j]; if (overlappingWallPieceOtherRoom && overlappingWallPieceThisRoom) { if ((overlappingWallPieceOtherRoom.WallPieceType == WallPieceType.DownRight) && overlappingWallPieceThisRoom.WallPieceType == WallPieceType.UpLeft) { overlappingWallPieceOtherRoom.gameObject.SetActive(false); overlappingWallPieceOtherRoom.SetWallSprite(WallPieceDisplayMode.Visible); } if ((overlappingWallPieceThisRoom.WallPieceType == WallPieceType.DownRight) && overlappingWallPieceOtherRoom.WallPieceType == WallPieceType.UpLeft) { overlappingWallPieceThisRoom.gameObject.SetActive(false); overlappingWallPieceThisRoom.SetWallSprite(WallPieceDisplayMode.Visible); } if ((overlappingWallPieceOtherRoom.WallPieceType == WallPieceType.DownLeft) && overlappingWallPieceThisRoom.WallPieceType == WallPieceType.UpRight) { overlappingWallPieceOtherRoom.gameObject.SetActive(false); overlappingWallPieceOtherRoom.SetWallSprite(WallPieceDisplayMode.Visible); } if ((overlappingWallPieceThisRoom.WallPieceType == WallPieceType.DownLeft) && overlappingWallPieceOtherRoom.WallPieceType == WallPieceType.UpRight) { overlappingWallPieceThisRoom.gameObject.SetActive(false); overlappingWallPieceThisRoom.SetWallSprite(WallPieceDisplayMode.Visible); } } } } }
public void BuildWall() { foreach (WallPiece piece in pieces) { if (piece) { Destroy(piece.gameObject); } } pieces = new List <WallPiece> (); Vector3 direction = transform.right; for (int i = -segmentAmount; i <= segmentAmount; i++) { GameObject newSegment = Instantiate(wallPrefab, transform.position + direction * segmentLength * i, transform.rotation); newSegment.transform.SetParent(transform); WallPiece piece = newSegment.GetComponent <WallPiece> (); pieces.Add(piece); } }
public static void ReenableWallpiecesFromAdjacentRooms(Room room) { // after a neighbour room is deleted, go over all wallpieces in this room to check if any wallpieces now do not overlap but are disabled. Reenable these List <BuildingTile> edgeTileClustersWithOverlap = room.RoomEdgeTilesPerCluster.Where(tile => tile.BuildingTileRooms.Count > 1).ToList(); List <Room> roomsStartingOnEdgeTile = new List <Room>(); for (int j = 0; j < edgeTileClustersWithOverlap.Count; j++) { BuildingTile edgeTileClusterWithOverlap = edgeTileClustersWithOverlap[j]; for (int p = 0; p < edgeTileClusterWithOverlap.BuildingTileRooms.Count; p++) { Room overlappingRoom = edgeTileClusterWithOverlap.BuildingTileRooms[p]; if (overlappingRoom.RoomCorners[Direction.Down].x == edgeTileClusterWithOverlap.StartingPoint.x && overlappingRoom.RoomCorners[Direction.Down].y == edgeTileClusterWithOverlap.StartingPoint.y) { roomsStartingOnEdgeTile.Add(overlappingRoom); } } } // rooms that have the down corner on along the edge of this room for (int i = 0; i < edgeTileClustersWithOverlap.Count; i++) { BuildingTile tileWithOverlap = edgeTileClustersWithOverlap[i]; List <WallPiece> wallPiecesAllRooms = new List <WallPiece>(); for (int k = 0; k < tileWithOverlap.BuildingTileRooms.Count; k++) { Room otherRoom = tileWithOverlap.BuildingTileRooms[k]; wallPiecesAllRooms.AddRange(Room.GetWallpiecesByAnyBuildingTile(tileWithOverlap.StartingPoint, otherRoom)); } List <WallPiece> activeWallPiecesFromThisRoom = wallPiecesAllRooms.Where(wallPiece => wallPiece.Room.Id == room.Id).ToList(); if (activeWallPiecesFromThisRoom.Count == 0) { continue; } for (int j = 0; j < activeWallPiecesFromThisRoom.Count; j++) { WallPiece activeWallPiece = activeWallPiecesFromThisRoom[j]; if (activeWallPiece.WallPieceType == WallPieceType.UpLeft || activeWallPiece.WallPieceType == WallPieceType.DownLeft) // UpLeft for continuing wall parts, DownLeft at the bottom corner { if (activeWallPiece.transform.position.x == 0) { Logger.Log("For this tile at {0},{1} the type is {2}", activeWallPiece.transform.position.x, activeWallPiece.transform.position.y, activeWallPiece.WallPieceType); Logger.Log("This room downside is {0},{1}, with the id {2}", room.RoomCorners[Direction.Down].x, room.RoomCorners[Direction.Down].y, room.Id); } List <WallPiece> oppositeWallPieces = wallPiecesAllRooms.Where(wallPiece => wallPiece.WallPieceType == WallPieceType.DownRight).ToList(); for (int k = 0; k < oppositeWallPieces.Count; k++) { WallPiece oppositeWallPiece = oppositeWallPieces[k]; if (activeWallPiece.transform.position.x == 0) { Logger.Log("oppositeWallPiece at {0},{1} the type is {2}", oppositeWallPiece.transform.position.x, oppositeWallPiece.transform.position.y, oppositeWallPiece.WallPieceType); } // only if not corner piece if (!wallPiecesAllRooms.Any(wallPiece => wallPiece.WallPieceType == WallPieceType.UpRight && wallPiece.Room.Id != room.Id)) { oppositeWallPiece.gameObject.SetActive(true); if (oppositeWallPiece.Room.CharactersInRoom.Count > 0) { oppositeWallPiece.SetWallSprite(WallPieceDisplayMode.Transparent); } } oppositeWallPiece.Room.WallPieces.Where( wallPiece => wallPiece.WallPieceType == WallPieceType.DownRight && wallPiece.transform.position.x == tileWithOverlap.StartingPoint.x + 5 && wallPiece.transform.position.y == tileWithOverlap.StartingPoint.y + 2.5f && room.WallPieces.Any(wallPieceThisRoom => wallPieceThisRoom.transform.position.x == tileWithOverlap.StartingPoint.x + 5 && wallPieceThisRoom.transform.position.y == tileWithOverlap.StartingPoint.y + 2.5f)) .ToList() .ForEach(wallPiece => { wallPiece.gameObject.SetActive(true); if (wallPiece.Room.CharactersInRoom.Count > 0) { wallPiece.SetWallSprite(WallPieceDisplayMode.Transparent); } }); oppositeWallPiece.Room.WallPieces.Where( wallPiece => wallPiece.WallPieceType == WallPieceType.DownRight && wallPiece.transform.position.x == tileWithOverlap.StartingPoint.x + 10 && wallPiece.transform.position.y == tileWithOverlap.StartingPoint.y + 5f && room.WallPieces.Any(wallPieceThisRoom => wallPieceThisRoom.transform.position.x == tileWithOverlap.StartingPoint.x + 10 && wallPieceThisRoom.transform.position.y == tileWithOverlap.StartingPoint.y + 5f)) .ToList() .ForEach(wallPiece => { wallPiece.gameObject.SetActive(true); if (wallPiece.Room.CharactersInRoom.Count > 0) { wallPiece.SetWallSprite(WallPieceDisplayMode.Transparent); } }); } //for dealing with corners for (int l = 0; l < roomsStartingOnEdgeTile.Count; l++) { Room roomStartingOnEdgeTile = roomsStartingOnEdgeTile[l]; Vector2 roomStartingOnEdgeTileLocation = roomStartingOnEdgeTile.RoomCorners[Direction.Down]; // check if there is a wallpiece intersecting the corner if (activeWallPiece.transform.position.x == roomStartingOnEdgeTileLocation.x && activeWallPiece.transform.position.y == roomStartingOnEdgeTileLocation.y && (activeWallPiece.transform.position.x != room.RoomCorners[Direction.Up].x && activeWallPiece.transform.position.y != room.RoomCorners[Direction.Up].y)) { for (int n = 0; n < roomStartingOnEdgeTile.WallPieces.Count; n++) { WallPiece wallPiece = roomStartingOnEdgeTile.WallPieces[n]; if ((wallPiece.transform.position.x == roomStartingOnEdgeTileLocation.x + 5 && wallPiece.transform.position.y == roomStartingOnEdgeTileLocation.y + 2.5f) || (wallPiece.transform.position.x == roomStartingOnEdgeTileLocation.x + 10 && wallPiece.transform.position.y == roomStartingOnEdgeTileLocation.y + 5f)) { wallPiece.gameObject.SetActive(true); if (wallPiece.Room.CharactersInRoom.Count > 0) { wallPiece.SetWallSprite(WallPieceDisplayMode.Transparent); } } } Logger.Log("There is something on the corner"); } } } if (activeWallPiece.WallPieceType == WallPieceType.UpRight) { List <WallPiece> oppositeWallPieces = wallPiecesAllRooms.Where(wallPiece => wallPiece.WallPieceType == WallPieceType.DownLeft).ToList(); for (int k = 0; k < oppositeWallPieces.Count; k++) { WallPiece oppositeWallPiece = oppositeWallPieces[k]; oppositeWallPiece.gameObject.SetActive(true); if (oppositeWallPiece.Room.CharactersInRoom.Count > 0) { oppositeWallPiece.SetWallSprite(WallPieceDisplayMode.Transparent); } oppositeWallPiece.Room.WallPieces.Where( wallPiece => wallPiece.WallPieceType == WallPieceType.DownLeft && wallPiece.transform.position.x == tileWithOverlap.StartingPoint.x + 5 && wallPiece.transform.position.y == tileWithOverlap.StartingPoint.y - 2.5f ) .ToList() .ForEach(wallPiece => { wallPiece.gameObject.SetActive(true); if (wallPiece.Room.CharactersInRoom.Count > 0) { wallPiece.SetWallSprite(WallPieceDisplayMode.Transparent); } }); oppositeWallPiece.Room.WallPieces.Where( wallPiece => wallPiece.WallPieceType == WallPieceType.DownLeft && wallPiece.transform.position.x == tileWithOverlap.StartingPoint.x + 10 && wallPiece.transform.position.y == tileWithOverlap.StartingPoint.y - 5f ) .ToList() .ForEach(wallPiece => { wallPiece.gameObject.SetActive(true); if (wallPiece.Room.CharactersInRoom.Count > 0) { wallPiece.SetWallSprite(WallPieceDisplayMode.Transparent); } }); } } } } }
// this room is the room that is left public static void RaiseWallPieces(Room room) { List <BuildingTile> edgeTileClustersWithOverlap = room.RoomEdgeTilesPerCluster.Where(tile => tile.BuildingTileRooms.Count > 1).ToList(); for (int i = 0; i < room.WallPieces.Count; i++) { WallPiece wallPiece = room.WallPieces[i]; if (wallPiece.WallPieceType == WallPieceType.DownLeft || wallPiece.WallPieceType == WallPieceType.DownRight) { if (wallPiece.gameObject.activeSelf) { wallPiece.SetWallSprite(WallPieceDisplayMode.Visible); } else { //find the corresponding wall piece in the other room and activate that List <WallPiece> overlappingOtherRoomWallPieces = new List <WallPiece>(); for (int j = 0; j < room.AdjacentRooms.Count; j++) { overlappingOtherRoomWallPieces.AddRange(room.AdjacentRooms[j].WallPieces.Where(otherWallPiece => otherWallPiece.transform.position == wallPiece.transform.position).ToList()); } for (int k = 0; k < overlappingOtherRoomWallPieces.Count; k++) { WallPiece overlappingOtherRoomWallPiece = overlappingOtherRoomWallPieces[k]; if (wallPiece.transform.position.x == 30 && wallPiece.transform.position.y == 0) { Logger.Log("RAISE wall pieces for {0}, {1}", wallPiece.transform.position.x, wallPiece.transform.position.y); Logger.Log("wallPiece type {0}", wallPiece.WallPieceType); Logger.Log("overlappingOtherRoomWallPiece type {0}", overlappingOtherRoomWallPiece.WallPieceType); } if (overlappingOtherRoomWallPiece.gameObject.activeSelf) { if (wallPiece.WallPieceType == WallPieceType.DownLeft) { if (overlappingOtherRoomWallPiece.WallPieceType == WallPieceType.UpLeft) { if (overlappingOtherRoomWallPiece.Room.CharactersInRoom.Count > 0) { continue; } WallPiece downRightWallPiece = overlappingOtherRoomWallPieces.FirstOrDefault(overlappingWallPiece => overlappingWallPiece.WallPieceType == WallPieceType.DownRight); if (downRightWallPiece && downRightWallPiece.Room.CharactersInRoom.Count > 0) { continue; } } } if (wallPiece.WallPieceType == WallPieceType.DownRight) { if (overlappingOtherRoomWallPiece.WallPieceType == WallPieceType.UpRight) { if (overlappingOtherRoomWallPiece.Room.CharactersInRoom.Count > 0) { continue; } WallPiece downLeftWallPiece = overlappingOtherRoomWallPieces.FirstOrDefault(overlappingWallPiece => overlappingWallPiece.WallPieceType == WallPieceType.DownLeft); if (downLeftWallPiece && downLeftWallPiece.Room.CharactersInRoom.Count > 0) { continue; } } } overlappingOtherRoomWallPiece.SetWallSprite(WallPieceDisplayMode.Visible); } } } } List <BuildingTile> overlappingTileClusters = edgeTileClustersWithOverlap.Where(edgeTile => (edgeTile.StartingPoint == new Vector2(wallPiece.transform.position.x, wallPiece.transform.position.y))).ToList(); if (overlappingTileClusters.Count == 0) { continue; } BuildingTile overlappingTile = overlappingTileClusters[0]; // take any tile, because the starting positions should be the same List <WallPiece> overlappingWallPieces = new List <WallPiece>(); for (int k = 0; k < overlappingTile.BuildingTileRooms.Count; k++) { Room otherRoom = overlappingTile.BuildingTileRooms[k]; if (otherRoom == room) { continue; } overlappingWallPieces.AddRange(Room.GetWallpiecesByAnyBuildingTile(overlappingTile.StartingPoint, otherRoom)); } for (int j = 0; j < overlappingWallPieces.Count; j++) { WallPiece overlappingWallPiece = overlappingWallPieces[j]; if (overlappingWallPiece == wallPiece) { continue; } // it is a corner, intersecting downleft in a corner to the right if (wallPiece.WallPieceType == WallPieceType.DownLeft) { //Logger.Warning("we found the common tile!! {0},{1}. Make it visible DownLeft", wallPiece.transform.position.x, wallPiece.transform.position.y); if ((overlappingWallPiece.WallPieceType == WallPieceType.DownRight) && overlappingWallPiece.Room.CharactersInRoom.Count == 0 ) { //get wall pieces from 1 tile up right. Check if there is a DownRight wallpiece which more than 1 person in the room. If so, continuel Room corneringRoom = RoomManager.Rooms.FirstOrDefault(r => r.RoomCorners[Direction.Down].x == wallPiece.transform.position.x && r.RoomCorners[Direction.Down].y == wallPiece.transform.position.y); if (corneringRoom && corneringRoom.CharactersInRoom.Count > 0) { continue; } RaiseWallPiece(new Vector2(wallPiece.transform.position.x + 5, wallPiece.transform.position.y + 2.5f), room); RaiseWallPiece(new Vector2(wallPiece.transform.position.x + 10, wallPiece.transform.position.y + 5f), room); } } if (wallPiece.WallPieceType == WallPieceType.UpLeft) { if ((overlappingWallPiece.WallPieceType == WallPieceType.DownRight) && overlappingWallPiece.Room.CharactersInRoom.Count == 0 ) { WallPiece downRightWallPiece = overlappingWallPieces.FirstOrDefault( w => w.WallPieceType == WallPieceType.DownRight && w.Room.Id != overlappingWallPiece.Room.Id); if (downRightWallPiece && downRightWallPiece.Room.CharactersInRoom.Count > 0) { continue; } Room corneringRoom = RoomManager.Rooms.FirstOrDefault(r => r.RoomCorners[Direction.Down].x == wallPiece.transform.position.x && r.RoomCorners[Direction.Down].y == wallPiece.transform.position.y); if (corneringRoom && corneringRoom.CharactersInRoom.Count > 0) { continue; } wallPiece.SetWallSprite(WallPieceDisplayMode.Visible); RaiseWallPiece(new Vector2(wallPiece.transform.position.x + 5, wallPiece.transform.position.y + 2.5f), room); RaiseWallPiece(new Vector2(wallPiece.transform.position.x + 10, wallPiece.transform.position.y + 5f), room); //if there is no cornering piece of type UpRight at same location if (!room.WallPieces.Any(piece => piece.transform.position == wallPiece.transform.position && piece.WallPieceType == WallPieceType.UpRight)) { RaiseWallPiece(new Vector2(wallPiece.transform.position.x + 5, wallPiece.transform.position.y - 2.5f), room); RaiseWallPiece(new Vector2(wallPiece.transform.position.x + 10, wallPiece.transform.position.y - 5f), room); } } } } } }
public static void LowerWallPiece(Vector2 overlapPosition, Room thisRoom, Room otherRoom) { List <WallPiece> overlappingWallPiecesThisRoom = Room.GetWallpiecesByAnyBuildingTile(overlapPosition, thisRoom); List <WallPiece> overlappingWallPiecesOtherRoom = Room.GetWallpiecesByAnyBuildingTile(overlapPosition, otherRoom); for (int i = 0; i < overlappingWallPiecesThisRoom.Count; i++) { WallPiece overlappingWallPieceThisRoom = overlappingWallPiecesThisRoom[i]; for (int j = 0; j < overlappingWallPiecesOtherRoom.Count; j++) { WallPiece overlappingWallPieceOtherRoom = overlappingWallPiecesOtherRoom[j]; if (overlappingWallPieceOtherRoom && overlappingWallPieceThisRoom) { if ((overlappingWallPieceOtherRoom.WallPieceType == WallPieceType.DownRight) && overlappingWallPieceThisRoom.WallPieceType == WallPieceType.UpLeft) { if (otherRoom.CharactersInRoom.Count < 1) { continue; } if (!overlappingWallPieceThisRoom.gameObject.activeSelf) { continue; } overlappingWallPieceThisRoom.SetWallSprite(WallPieceDisplayMode.Transparent); } if ((overlappingWallPieceThisRoom.WallPieceType == WallPieceType.DownRight) && overlappingWallPieceOtherRoom.WallPieceType == WallPieceType.UpLeft) { if (thisRoom.CharactersInRoom.Count < 1) { continue; } if (!overlappingWallPieceOtherRoom.gameObject.activeSelf) { continue; } overlappingWallPieceOtherRoom.SetWallSprite(WallPieceDisplayMode.Transparent); } if ((overlappingWallPieceOtherRoom.WallPieceType == WallPieceType.DownLeft) && overlappingWallPieceThisRoom.WallPieceType == WallPieceType.UpRight) { if (otherRoom.CharactersInRoom.Count < 1) { continue; } if (!overlappingWallPieceThisRoom.gameObject.activeSelf) { continue; } overlappingWallPieceThisRoom.SetWallSprite(WallPieceDisplayMode.Transparent); } if ((overlappingWallPieceThisRoom.WallPieceType == WallPieceType.DownLeft) && overlappingWallPieceOtherRoom.WallPieceType == WallPieceType.UpRight) { if (thisRoom.CharactersInRoom.Count < 1) { continue; } if (!overlappingWallPieceOtherRoom.gameObject.activeSelf) { continue; } overlappingWallPieceOtherRoom.SetWallSprite(WallPieceDisplayMode.Transparent); } } } } }
// Make sure that wall pieces of all room prefabs are on the correct location. Because if they are not lining up, it can break the wall visibility. public void ConfirmWallPiecesAlign() { Console.Instance.PrintToReportText("\n-----------------------------------------\n"); Console.Instance.PrintToReportText("Starting alignment analysis of wallpieces\n"); GameObject testRoomContainer = GameObject.Instantiate(new GameObject()); int problemCount = 0; foreach (KeyValuePair <RoomName, Dictionary <ObjectRotation, GameObject> > prefabGroup in BuilderManager.Instance.RegisteredRoomPrefabs) { RoomName roomName = prefabGroup.Key; GameObject prefabGO = prefabGroup.Value[ObjectRotation.Rotation0]; GameObject roomGO = GameObject.Instantiate(prefabGO, testRoomContainer.transform); Room room = roomGO.GetComponent <Room>(); for (int i = 0; i < room.WallPieces.Count; i++) { WallPiece wallPiece = room.WallPieces[i]; float xPosition = wallPiece.transform.position.x; float yPosition = wallPiece.transform.position.y; // check position if (xPosition % 5 != 0 || yPosition % 2.5f != 0) { string printLine = "The wall piece <b>" + wallPiece.name + "</b> in room <b>" + room.name + "</b> is not aligned with the grid. Its coordinates are " + xPosition + "," + yPosition + "\n"; if (xPosition % 5 != 0) { printLine += "<color=red> - wallPiece.transform.position.x % 5 = " + (xPosition % 5 + "</color>\n"); } else { printLine += " - wallPiece.transform.position.x % 5 = " + (xPosition % 5 + "\n"); } if (yPosition % 5 != 0) { printLine += "<color=red> - wallPiece.transform.position.y % 2.5f = " + (yPosition % 2.5f + "</color>\n"); } else { printLine += " - wallPiece.transform.position.y % 2.5f = " + (yPosition % 2.5f + "\n"); } Console.Instance.PrintToReportText(printLine); } } } Console.Instance.PrintToReportText("-----------------------------------------\n"); if (problemCount > 0) { Console.Instance.PrintToReportText("\nFinished analysis. <color=red>There were " + problemCount + " problems.</color>\n"); } else { Console.Instance.PrintToReportText("\nFinished analysis. <color=green>All wall pieces are aligned correctly!</color>\n"); } GameObject.Destroy(testRoomContainer); }