示例#1
0
    public void GenerateGrid(int rows = -1, int columns = -1)
    {
        ClearGrid();

        if (rows > 0)
        {
            m_rows = rows;
        }
        if (columns > 0)
        {
            m_columns = columns;
        }

        m_Grid = new TileScript[m_rows, m_columns];

        for (int r = 0; r < m_rows; r++)
        {
            for (int c = 0; c < m_columns; c++)
            {
                GameObject newTile = GameObject.Instantiate(_tilePrefab);
                newTile.name = "Tile " + r + ", " + c;
                newTile.transform.SetParent(GridRoot.transform);

                TileScript tile_ref = newTile.GetComponent <TileScript>();
                tile_ref.InitializeTile(r, c);
                m_Grid[r, c] = tile_ref;
            }
        }
    }