private void GenerateLevel(RoomNode node, RoomTransformation prevChunk) { //Place the Chunk somewhere, where it won't collide with another chunk GameObject chunk = InstantiateChunk(node, new Vector3(tmpChunkPos, 0f, tmpChunkStep)); if (isConstraintError) { return; } tmpChunkPos += tmpChunkStep; //Obtain the actual position, the chunk will have later on Vector3 chunkSize = ChunkSize(chunk); RoomTransformation roomTransform = new RoomTransformation(chunk, node.Position, chunkSize, spacing); roomTransform.AddConnection(prevChunk); positionMeta.Add(roomTransform); debugData.AddRoomMeta(chunk, node); if (prevChunk != null) { HallwayMeta hallway = prevChunk.FindMatchingDoors(roomTransform); hallwayMeta.Add(hallway); } //Recursively generate subrooms foreach (RoomNode subNode in node.Connections) { GenerateLevel(subNode, roomTransform); } }
//Is neccessary to calculate the furthest distance (see below) //Will store a reference to a connecting room and vice versa public void AddConnection(RoomTransformation otherChunk) { if (!connections.Contains(otherChunk) && otherChunk != null) { connections.Add(otherChunk); otherChunk.AddConnection(this); } }