Room GetRoomToConnectWith(ConnectionPoint.ConnectionType connectionType) { roomPrefabs.Shuffle(); for (int j = 0; j < roomPrefabs.Length; j++) { var bit = roomPrefabs[j]; if (connectionType == ConnectionPoint.ConnectionType.ANY) { return(bit); } var connectors = bit.GetConnections(); // look in the level bit and see if it has a valid connection point foreach (var cp in connectors) { Debug.Log("connects to: " + cp.connectionType); if (cp.connectionType == ConnectionPoint.ConnectionType.ANY || cp.connectionType == connectionType) { return(bit); } } } return(null); }
Connector GetConnectorForConnectionType(ConnectionPoint.ConnectionType connectionType) { connectorPrefabs.Shuffle(); foreach (var connector in connectorPrefabs) { if (connectionType == ConnectionPoint.ConnectionType.ANY) { return(connector); } if (connectionType == ConnectionPoint.ConnectionType.DOOR && (connector.end1 == null != connector.end2 == null) || connectionType == ConnectionPoint.ConnectionType.HALLWAY && connector.end1 != null && connector.end2 != null) { return(connector); } } Debug.LogWarning("No connector found to fit connection type " + connectionType); return(null); }
public override DungeonGridCell CreateRoom(DungeonManager p_gen, DungeonTheme p_dungeonTheme, Vector3Int p_roomPosition, DungeonGridCell p_currentCell, DungeonGridCell[,] p_allCells, ref int[,] p_dungeonGrid) { Vector2Int bounds = new Vector2Int(m_cellSize.x - m_cellBoarder, m_cellSize.y - m_cellBoarder); Vector2Int roomSize = new Vector2Int(Random.Range(m_minRoomSize.x, m_maxRoomSize.x), Random.Range(m_minRoomSize.y, m_maxRoomSize.y)); Vector2Int randomStart = new Vector2Int(Random.Range(m_cellBoarder, bounds.x - roomSize.x), Random.Range(m_cellBoarder, bounds.y - roomSize.y)); //p_currentCell.m_worldPos = new Vector3(randomStart.x + p_roomPosition.x + .5f, randomStart.y + p_roomPosition.y + .5f); p_currentCell.m_worldPos = new Vector3(randomStart.x + p_roomPosition.x + ((float)roomSize.x / 2), randomStart.y + p_roomPosition.y + ((float)roomSize.y / 2)); p_currentCell.m_roomSize = roomSize; Vector3 pos = p_currentCell.m_worldPos; //GameObject.Instantiate(m_debugCube, pos - Vector3.forward*3, Quaternion.identity); List <Vector2> floorTiles = new List <Vector2>(); for (int x = randomStart.x; x < roomSize.x + randomStart.x; x++) { for (int y = randomStart.y; y < roomSize.y + randomStart.y; y++) { p_dungeonGrid[x + p_roomPosition.x, y + p_roomPosition.y] = 1; //GameObject.Instantiate(m_debugCube2, new Vector3(p_roomPosition.x + x + .5f, p_roomPosition.y +y + .5f), Quaternion.identity); if (x > randomStart.x && x < roomSize.x + randomStart.x - 1 && y > randomStart.y && y < roomSize.y + randomStart.y - 1) { floorTiles.Add(new Vector2(x + p_roomPosition.x, y + p_roomPosition.y)); } } } p_currentCell.m_floorTiles = floorTiles; for (int x = -1; x < 2; x++) { for (int y = -1; y < 2; y++) { if (x == 0 && y == 0 || x == -1 && y != 0 || x == 1 && y != 0 || x != 0 && y == -1 || x != 0 && y == 1) { continue; } if (x + p_currentCell.m_gridPosition.x < 0 || x + p_currentCell.m_gridPosition.x > m_cellsInDungeon.x - 1) { continue; } if (y + p_currentCell.m_gridPosition.y < 0 || y + p_currentCell.m_gridPosition.y > m_cellsInDungeon.y - 1) { continue; } if (p_allCells[x + p_currentCell.m_gridPosition.x, y + p_currentCell.m_gridPosition.y].m_connectedTo.Contains(p_currentCell.m_gridPosition)) { continue; } if (p_allCells[x + p_currentCell.m_gridPosition.x, y + p_currentCell.m_gridPosition.y].m_currentCellType == DungeonGridCell.CellType.Hallway || p_allCells[x + p_currentCell.m_gridPosition.x, y + p_currentCell.m_gridPosition.y].m_currentCellType == DungeonGridCell.CellType.Room) { Vector3Int connectionPos = new Vector3Int(); ConnectionPoint.ConnectionType connectType = ConnectionPoint.ConnectionType.Node; if (y > 0) { connectionPos = new Vector3Int(Random.Range(0, roomSize.x) + p_roomPosition.x + randomStart.x, roomSize.y + p_roomPosition.y + randomStart.y, 0); connectType = ConnectionPoint.ConnectionType.Up; } else if (y < 0) { connectionPos = new Vector3Int(Random.Range(0, roomSize.x) + p_roomPosition.x + randomStart.x, p_roomPosition.y + randomStart.y - 1, 0); connectType = ConnectionPoint.ConnectionType.Down; } else if (x > 0) { connectionPos = new Vector3Int(roomSize.x + p_roomPosition.x + randomStart.x, Random.Range(0, roomSize.y) + p_roomPosition.y + randomStart.y, 0); connectType = ConnectionPoint.ConnectionType.Right; } else if (x < 0) { connectionPos = new Vector3Int(p_roomPosition.x + randomStart.x - 1, Random.Range(0, roomSize.y) + p_roomPosition.y + randomStart.y, 0); connectType = ConnectionPoint.ConnectionType.Left; } p_dungeonGrid[connectionPos.x, connectionPos.y] = 1; p_currentCell.AddConnectionPoint(connectionPos, connectType); } } } return(p_currentCell); }
public void AddConnectionPoint(Vector3Int p_position, ConnectionPoint.ConnectionType p_connectType) { m_connectionPoints.Add(new ConnectionPoint(p_position, p_connectType)); }