public void Generate()
    {
        InstancedTiles      = new GameObject[size, size];
        DungeonTerrainTiles = new DungeonTerrainTile[size, size];
        Rooms = new List <Room>();

        for (int i = 0; i < attempts; i++)
        {
            CreateRoom(roomSize.x, roomSize.y);
        }

        mesh = DelaunayTriangulation.TriangulatePoints(centerWorldTiles);
        spanningTree.AddRange(MST.FormTree(mesh, centerWorldTiles.Count, generateExtraEdges));

        for (int i = 0; i < spanningTree.Count; i++)
        {
            CreatePaths(spanningTree[i].edge);
        }
        onComplete?.Invoke();

        if (instantiateDebugTiles)
        {
            InstantiateTiles();
        }
    }
    void CreateRoom(int min, int max)
    {
        Vector2Int randomTile = new Vector2Int(Random.Range(0, size), Random.Range(0, size));
        Room       room       = new Room();

        int roomSizeX = Random.Range(min, max);
        int roomSizeY = Random.Range(min, max);

        //If room goes over beyod grid return
        if (roomSizeX + randomTile.x > size || roomSizeY + randomTile.y > size)
        {
            return;
        }

        int minX = randomTile.x - roomSpacing;
        int minY = randomTile.y - roomSpacing;

        int maxX = randomTile.x + roomSizeX + roomSpacing;
        int maxY = randomTile.y + roomSizeY + roomSpacing;

        Vector2Int centerTile = new Vector2Int((randomTile.x + roomSizeX / 2), (randomTile.y + roomSizeY / 2));

        //Checks if room boundaries are inside the grid
        if (minX < 0 || minY < 0 || maxX > size || maxY > size)
        {
            return;
        }

        //Checks if there are any tiles in room boundaries
        for (int x = minX; x < maxX; x++)
        {
            for (int y = minY; y < maxY; y++)
            {
                if (DungeonTerrainTiles[x, y] != null)
                {
                    return;
                }
            }
        }

        centerWorldTiles.Add(grid.GetCellCenterWorld(new Vector3Int(centerTile.x, 0, centerTile.y)));

        //Room Walls
        for (int x = randomTile.x; x <= randomTile.x + roomSizeX; x++)
        {
            for (int y = randomTile.y; y <= randomTile.y + roomSizeY; y++)
            {
                if (x == randomTile.x || y == randomTile.y || x == randomTile.x + roomSizeX || y == randomTile.y + roomSizeY)
                {
                    DungeonTerrainTiles[x, y] = new DungeonTerrainTile(DungeonTerrainTile.TileType.Wall);
                }
            }
        }

        //Room Floor
        for (int x = randomTile.x + 1; x <= randomTile.x + roomSizeX - 1; x++)
        {
            for (int y = randomTile.y + 1; y <= randomTile.y + roomSizeY - 1; y++)
            {
                DungeonTerrainTiles[x, y] = new DungeonTerrainTile(DungeonTerrainTile.TileType.Floor);
            }
        }

        room.centerGridTile = new Vector3Int(centerTile.x, centerTile.y, 0);
        room.minX           = randomTile.x;
        room.maxX           = randomTile.x + roomSizeX;

        room.minY = randomTile.y;
        room.maxY = randomTile.y + roomSizeY;

        Rooms.Add(room);

        return;
    }