//Puzzle creation
    private void CreatePuzzle()
    {
        //Disable Game Over Panel
        GameOverPanel.SetActive(false);

        Image[] imageComponentBlock = new Image[BlocksPerLine * BlocksPerLine];
        
        Blocks = new Block[BlocksPerLine, BlocksPerLine];
        ImageSlices = ImageSlicer.GetSpriteSlices(ImageSprite, BlocksPerLine);

        //Auto Grid Layout For Column Arranging
        AutoGridLayout autoGridLayout = transform.Find("GameFieldParent").Find("GameField").GetComponent<AutoGridLayout>();
        autoGridLayout._column = BlocksPerLine;

        //Add Outline
        //transform.Find("GameFieldParent").Find("GameField").GetComponent<Outline>().enabled = true;

        //Creating Image GameObject Component
        for (int i = 0; i< BlocksPerLine * BlocksPerLine; i++)
        {
            GameObject newObj = new GameObject("Block");
            Image newImage = newObj.AddComponent<Image>();
            imageComponentBlock[i] = newImage;
            newObj.GetComponent<RectTransform>().SetParent(transform.Find("GameFieldParent").Find("GameField"));
        }

        //Creating grid with block component.
        for (int row = 0; row < BlocksPerLine; row++)
        {
            for (int column = 0; column < BlocksPerLine; column++)
            {
                foreach (Image singleImage in imageComponentBlock)
                {
                    if (singleImage.gameObject.GetComponent<Block>() == null)
                    {
                        //Adding Block Script To Game Object
                        Block block = singleImage.gameObject.AddComponent<Block>();
                        block.SetImage(ImageSlices[row, column]);
                        block.OnBlockPressed += MoveBlockByPlayer;
                        block.Number = 1;

                        block.Row = row;
                        block.Column = column;

                        if (row == BlocksPerLine - 1 && column == BlocksPerLine - 1)
                        {
                            block.Number = 0;
                            EmptyBlock = block;
                            EmptyRow = row;
                            EmptyColumn = column;
                        }
                        Blocks[row, column] = block;
                        break;
                    }
                }
            }
        }
    }
Esempio n. 2
0
    public void DrawSquare(int columns)
    {
        AutoGridLayout AGL = GridContainer.GetComponent <AutoGridLayout>();

        //Clear All Children
        foreach (Transform child in GridContainer.transform)
        {
            Destroy(child.gameObject);
        }

        AGL.m_Column = columns;

        //Generate Squares
        for (int i = 0; i < columns * columns; i++)
        {
            GameObject temp = Instantiate(Tile, Vector3.zero, Quaternion.identity) as GameObject;
            temp.transform.SetParent(GridContainer.transform, false);
            tiles.Add(temp.GetComponent <Tile>());
            tilesGO.Add(temp);
            emptyIndexes.Add(i);
            tiles[i].ApplyStyle();
        }
    }
Esempio n. 3
0
 void Awake()
 {
     autoGridLayout = this;
 }
Esempio n. 4
0
 void Awake()
 {
     autoGridLayout = this;
 }