Beispiel #1
0
    private void InitQuads()
    {
        Texture2D[,] slices = ImageSlicer.GetSlices(image, size);
        for (int y = 0; y < size; y++)
        {
            for (int x = 0; x < size; x++)
            {
                GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
                quad.transform.position = new Vector3(x - (size / 2f) + 0.5f, y - (size / 2f) + 0.5f, 0f);
                quad.transform.parent   = transform;

                PuzzlePiece puzzlePiece = quad.AddComponent <PuzzlePiece>();
                puzzlePiece.OnPuzzlePiecePressed         += EnqueuePuzzlePiece;
                puzzlePiece.OnPuzzlePieceFinishedSliding += OnPuzzlePieceFinishedMoving;
                puzzlePiece.Init(new Vector2Int(x, y), slices[y, x]);
                _puzzle[x, y] = puzzlePiece;

                if (y == 0 && x == size - 1)
                {
                    _hiddenPiece = puzzlePiece;
                }
            }
        }

        Camera.main.orthographicSize = size * 0.55f;
    }