Esempio n. 1
0
    public void ConstructGrid()
    {
        if (dungeonGrid == null)
        {
            return;
        }

        dungeonGrid.GenerateDungeon();

        Tile[,] dGrid = dungeonGrid.GetDungeonGrid();
        grid          = new Node[gridSizeX, gridSizeY];
        Vector3 bottomLeft = transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.forward * gridWorldSize.y / 2;

        for (int x = 0; x < gridSizeX; x++)
        {
            for (int y = 0; y < gridSizeY; y++)
            {
                float   xStep      = (x * nodeDiameter);
                float   yStep      = (y * nodeDiameter);
                Vector3 worldPoint = (bottomLeft + Vector3.right * xStep + Vector3.forward * yStep);

                bool isWalkable = false;

                if (dGrid[x, y] == Tile.path || dGrid[x, y] == Tile.room)
                {
                    isWalkable = true;
                }

                grid[x, y] = new Node(isWalkable, worldPoint, x, y);
            }
        }

        GetRooms();
    }