private RoomData FindFreeNeighbour(RoomData roomTobranchFrom) { RoomData newRoom; int searchAttempts = 0; do { searchAttempts++; newRoom = roomTobranchFrom.Copy(); bool moveHor = Random.value < 0.5f; int direction = Random.value < 0.5f ? 1 : -1; if (moveHor) { newRoom.GridPosition.x += direction; } else { newRoom.GridPosition.y += direction; } } while ((_roomDatas.Contains(newRoom) || (newRoom.GridPosition.x >= _gridSize) || (newRoom.GridPosition.y >= _gridSize) || (newRoom.GridPosition.x < 0) || (newRoom.GridPosition.y < 0)) && (searchAttempts < MaximumSearchAttempts)); return(newRoom); }