1. Create a room database
In the handy dandy CSV format. The first line designates the type of the room, which sides it contain doors (openings) on and if it can be rotated or not.
Room Base 1 1 0 0 r w,w,w,w,.,.,w,w,w,w w,l,w,w,.,.,w,w,l,w w,w,.,.,.,.,.,.,w,w w,w,.,.,.,.,.,.,w,w w,w,.,.,.,.,.,.,.,. w,w,.,.,.,.,.,.,.,. w,w,.,.,.,.,.,.,w,w w,w,.,.,.,.,.,.,w,w w,l,w,w,w,w,w,w,l,w w,w,w,w,w,w,w,w,w,w
Extremely easy to setup in LibreOffice Calc with conditional formatting,
Likewise easy to implement in Unity. Just read the file and split lines with comma as the separator.
(I'm not going to bore you with code)
2. Create a 5x5 grid
A multidimentional int array, nothing else is needed.
3. Set one of the corners as the goal
Just pick a random corner. No safeguards here.
4. Find a valid path from the center to the goal using random walk
Random walk: pick a random direction, keep track of positions already visited, back up if surrounded by walls or visited positions, stop if goal reached otherwise repeat. A recursive function works well here.
This results in all sorts of paths. At worst the whole grid is filled, but usually gives a pretty straight forward path. The random walk can be skewed towards the goal position by weighting the direction choosing part (I'm not doing this as you can see in the gif below)
5. Add a valid sequence of rooms to the path
Making sure the doors match. Other than that the rooms are completely random. This is where earmarking each room with its doors comes to great use.
6. Add random rooms to other positions.
The randomization can be weighted or otherwise limited here if the results looks silly. Rooms with less doors seem to work pretty well as they don't mess too much with the path.
The room database is the saving grace here. No need to worry about invalid connections or silly shapes as the rooms are authored by a human designer. Rotating them adds a surprising about of variation too and the FOV system hides the grid like shape of the level pretty well.