private void CreatePieces()
    {
        // Initialize variables
        int sliceSize = Mathf.Min(puzzleTexture.width / puzzleSize, puzzleTexture.height / puzzleSize);

        rowCount    = puzzleTexture.height / sliceSize;
        columnCount = puzzleTexture.width / sliceSize;

        slots  = new RectTransform[rowCount][];
        pieces = new SlidePuzzlePiece[rowCount][];

        for (int i = 0; i < rowCount; i++)
        {
            slots[i]  = new RectTransform[columnCount];
            pieces[i] = new SlidePuzzlePiece[columnCount];
        }

        slotsParent.aspectRatio = columnCount / (float)rowCount;

        // Slice puzzleTexture (starts from top-left corner)
        Texture2D[] slices = TextureOps.Slice(puzzleTexture, sliceSize, sliceSize, options: new TextureOps.Options(false, false, true));
        for (int i = 0; i < slices.Length; i++)
        {
            slices[i].wrapMode = TextureWrapMode.Clamp;             // To avoid artifacts at edges
        }
        // Create puzzle pieces
        float _1OverRowCount    = 1f / rowCount;
        float _1OverColumnCount = 1f / columnCount;

        for (int i = 0, sliceIndex = 0; i < rowCount; i++)          // Row, starting from top
        {
            for (int j = 0; j < columnCount; j++, sliceIndex++)     // Column, starting from left
            {
                RectTransform slot = new GameObject("Slot" + i + "x" + j).AddComponent <RectTransform>();
                slot.SetParent(slotsParent.transform, false);
                slot.anchorMin        = new Vector2(_1OverColumnCount * j, 1f - _1OverRowCount * (i + 1));
                slot.anchorMax        = new Vector2(_1OverColumnCount * (j + 1), 1f - _1OverRowCount * i);
                slot.sizeDelta        = new Vector2(0f, 0f);
                slot.anchoredPosition = new Vector2(0f, 0f);

                SlidePuzzlePiece piece = new GameObject("Piece").AddComponent <SlidePuzzlePiece>();
                piece.InitializeComponents(slices[sliceIndex], () => OnPieceClicked(piece));

                slots[i][j]  = slot;
                pieces[i][j] = piece;
            }
        }
    }
Exemple #2
0
        private void ChangeBrightness()
        {
            IEnumerable <string> files = FindAll(new [] { ".png", ".jpeg" });

            foreach (string sFilePath in files)
            {
                Texture2D loadedImage = TextureOps.LoadImage(sFilePath);
                if (loadedImage != null)
                {
                    Texture2D outTexture = loadedImage.AdjustBrightness(1);
                    TextureOps.SaveImage(outTexture, sFilePath);

                    CompareHash(sFilePath, loadedImage, outTexture);

                    DestroyImmediate(loadedImage);
                    DestroyImmediate(outTexture);
                }
            }
        }
Exemple #3
0
        private void ResizeAll()
        {
            IEnumerable <string> files = FindAll(new [] { ".png", ".jpeg" });

            foreach (string sFilePath in files)
            {
                Texture2D loadedImage = TextureOps.LoadImage(sFilePath);
                if (loadedImage != null)
                {
                    float w = loadedImage.width / 100f * 99f;
                    float h = loadedImage.height / 100f * 99f;

                    Texture2D scaledImage = TextureOps.Scale(loadedImage, (int)w, (int)h, TextureFormat.ARGB32);

                    CompareHash(sFilePath, loadedImage, scaledImage);

                    DestroyImmediate(loadedImage);
                    DestroyImmediate(scaledImage);
                }
            }
        }