예제 #1
0
    //Generates the tiles
    private void GenerateTiles(int dimension)
    {
#if UNITY_EDITOR
        BoardState.GenerateTileArray();
#endif

        Debug.Log("Generating Tiles of Dimension: " + dimension);
        //get the position where to lay the first empty tile
        Vector3 currentPos = GetTileStartPos(dimension);
        //rows
        for (int i = 0; i < dimension; i++)
        {
            //columns
            for (int j = 0; j < dimension; j++)
            {
                //instantiate new tile as a child of this object and then reset position
                GameObject newObject = Instantiate(emptyTile, currentPos, Quaternion.identity, gameObject.transform);
                EmptyTile  newTile   = newObject.GetComponent <EmptyTile>();
                newTile.TileValue = new Vector2Int(i, j);
                currentPos.x     += tileBounds.x + tileSpacing;

                #if UNITY_EDITOR
                BoardState.AddToTileArray(newTile);
                #endif
            }
            //set x and y for a new row
            currentPos.x  = GetTileStartPos(dimension).x;
            currentPos.y -= tileBounds.y + tileSpacing;
        }
    }