Ejemplo n.º 1
0
    //Extract and mask image-piece to be used as puzzle piece texture
    Texture2D ExtractFromImage(Texture2D _image, Piece _puzzlElement, int _x, int _y, int _elementBaseSize, Vector2 _elementSizeRatio)
    {
        //Get proper piece of image
        Color[] pixels = _image.GetPixels
                         (
            (int)((_x * _elementBaseSize - _puzzlElement.PixelOffset.x) * _elementSizeRatio.x),
            (int)(_image.height - (_y + 1) * _elementBaseSize * _elementSizeRatio.y - _puzzlElement.PixelOffset.height * _elementSizeRatio.y),
            (int)(_puzzlElement.MaskWidth * _elementSizeRatio.x),
            (int)(_puzzlElement.MaskHeight * _elementSizeRatio.y)
                         );


        Texture2D result = new Texture2D(
            (int)(_puzzlElement.MaskWidth * _elementSizeRatio.x),
            (int)(_puzzlElement.MaskHeight * _elementSizeRatio.y)
            );

        //Apply mask
        result.wrapMode = TextureWrapMode.Clamp;
        _puzzlElement.ApplyMask(pixels, ref result);

        return(result);
    }