public static void applyTextureToAnotherTexture(ref TextureColorArray source, ref TextureColorArray destination, IntVector2 centerInDestination)
    {
        _leftX  = centerInDestination.x - source.width / 2;
        _rightX = _leftX + source.width;
        _downY  = centerInDestination.y - source.height / 2;
        _topY   = _downY + source.height;

        _srcLeftX = _leftX < 0 ? -_leftX : 0;
        _srcDownY = _downY < 0 ? -_downY : 0;

        _leftX  = _leftX < 0                  ? 0                      : _leftX;
        _rightX = _rightX >= destination.width  ? destination.width    : _rightX;
        _downY  = _downY < 0                  ? 0                      : _downY;
        _topY   = _topY >= destination.height ? destination.height  : _topY;


        _srcY  = _srcDownY * source.width;
        _destY = _downY * destination.width;
        for (_y = _downY; _y < _topY; _y++)
        {
            _srcX = _srcLeftX;
            for (int _x = _leftX; _x < _rightX; _x++)
            {
                if (source.Colors [_srcY + _srcX].a > destination.Colors [_destY + _x].a)
                {
                    destination.Colors [_destY + _x] = source.Colors [_srcY + _srcX];
                }
                _srcX++;
            }
            _srcY  += source.width;
            _destY += destination.width;
        }
    }
    public static void applyTextureToAnotherTextureWithPixelRect(ref TextureColorArray source, ref TextureColorArray destination, IntVector2 centerInDestination)
    {
        Rect pixelRect = source.pixelRect;

        int leftX = (int)(centerInDestination.x - pixelRect.width / 2);
        int downY = (int)(centerInDestination.y - pixelRect.height / 2);


        int srcY = (int)pixelRect.y - 1;

        for (int y = downY; y < (downY + pixelRect.height); y++)
        {
            srcY++;
            int srcX = (int)pixelRect.x - 1;
            if (y < 0 || y >= destination.height)
            {
                continue;
            }
            for (int x = leftX; x < (leftX + pixelRect.width); x++)
            {
                srcX++;
                if (x < 0 || x >= destination.width)
                {
                    continue;
                }
                destination.Colors [y * destination.width + x] = source.Colors [srcY * source.width + srcX];
            }
        }
    }
Пример #3
0
    void applyStamp(IntVector2 position)
    {
        Color32[]         colors       = canvas.fetchColors();
        Color32           currentColor = PropertiesSingleton.instance.colorProperties.activeColor;
        Color32           secondColor  = PropertiesSingleton.instance.colorProperties.secondColor;
        TextureColorArray src          = new TextureColorArray(iconTexture.width, iconTexture.height, iconTexture.GetPixels32());
        TextureColorArray dst          = new TextureColorArray((int)canvas.size.x, (int)canvas.size.y, colors);

        TextureUtil.applyTextureToAnotherTexture(ref src, ref dst, position);
        for (int i = 0; i < colors.Length; i++)
        {
            if (colors[i].a > 0)
            {
                if (colors[i].r == 0)
                {
                    colors[i].r = secondColor.r;
                    colors[i].g = secondColor.g;
                    colors[i].b = secondColor.b;
                }
                else
                {
                    colors[i].r = currentColor.r;
                    colors[i].g = currentColor.g;
                    colors[i].b = currentColor.b;
                }
            }
        }
        canvas.applyColors(colors);
    }
Пример #4
0
    public static void applyTextureToAnotherTexture(ref TextureColorArray source, ref TextureColorArray destination, IntVector2 centerInDestination)
    {
        _leftX  = centerInDestination.x - source.width / 2;
        _rightX = _leftX + source.width;
        _downY  = centerInDestination.y - source.height / 2;
        _topY   = _downY + source.height;

        _srcLeftX = _leftX < 0 ? -_leftX : 0;
        _srcDownY = _downY < 0 ? -_downY : 0;

        _leftX  = _leftX  <  0                  ? 0                      : _leftX ;
        _rightX = _rightX >= destination.width  ? destination.width    : _rightX;
        _downY  = _downY  <  0                  ? 0                      : _downY ;
        _topY   = _topY   >= destination.height ? destination.height  : _topY  ;

        _srcY = _srcDownY * source.width;
        _destY = _downY * destination.width;
        for (_y = _downY; _y < _topY; _y++) {
            _srcX = _srcLeftX;
            for (int _x = _leftX; _x < _rightX; _x++) {

                if (source.Colors [_srcY  + _srcX].a > destination.Colors [_destY + _x].a)
                    destination.Colors [_destY + _x] = source.Colors [_srcY  + _srcX];
                _srcX ++;
            }
            _srcY  += source.width;
            _destY += destination.width;
        }
    }
    public static Color32[] generateTextureColorsByPatternAndPoint(int textureWidth, int textureHeight, Texture2D pattern, IntVector2 point)
    {
        Color32[]         newColors = new Color32[textureWidth * textureHeight];
        TextureColorArray src       = new TextureColorArray(pattern.width, pattern.height, pattern.GetPixels32());
        TextureColorArray dst       = new TextureColorArray(textureWidth, textureHeight, newColors);

        TextureUtil.applyTextureToAnotherTexture(ref src, ref dst, point);
        return(newColors);
    }
Пример #6
0
    public static void applyTextureToAnotherTextureWithPixelRect(ref TextureColorArray source, ref TextureColorArray destination, IntVector2 centerInDestination)
    {
        Rect pixelRect = source.pixelRect;

        int leftX = (int)(centerInDestination.x - pixelRect.width / 2);
        int downY = (int)(centerInDestination.y - pixelRect.height / 2);

        int srcY = (int)pixelRect.y - 1;
        for (int y = downY; y < (downY + pixelRect.height); y++) {
            srcY++;
            int srcX = (int)pixelRect.x - 1;
            if (y < 0 || y >= destination.height)
                continue;
            for (int x = leftX; x < (leftX + pixelRect.width); x++) {
                srcX ++;
                if (x < 0 || x >= destination.width)
                    continue;
                destination.Colors [y * destination.width + x] = source.Colors [srcY * source.width + srcX];
            }
        }
    }
Пример #7
0
 void applyStamp(IntVector2 position)
 {
     Color32[] colors= canvas.fetchColors();
     Color32 currentColor = PropertiesSingleton.instance.colorProperties.activeColor;
     Color32 secondColor = PropertiesSingleton.instance.colorProperties.secondColor;
     TextureColorArray src = new TextureColorArray (iconTexture.width, iconTexture.height, iconTexture.GetPixels32 ());
     TextureColorArray dst = new TextureColorArray ((int)canvas.size.x, (int)canvas.size.y, colors);
     TextureUtil.applyTextureToAnotherTexture (ref src, ref dst, position);
     for (int i = 0; i < colors.Length; i++) {
         if (colors[i].a > 0){
             if (colors[i].r == 0){
                 colors[i].r = secondColor.r;
                 colors[i].g = secondColor.g;
                 colors[i].b = secondColor.b;
             } else {
                 colors[i].r = currentColor.r;
                 colors[i].g = currentColor.g;
                 colors[i].b = currentColor.b;
             }
         }
     }
     canvas.applyColors(colors);
 }
Пример #8
0
    public static Color32[] generateTextureColorsByPatternAndPoints(int textureWidth, int textureHeight, Texture2D pattern, List<IntVector2> points)
    {
        Color32[] newColors = new Color32[textureWidth * textureHeight];

        TextureColorArray src = new TextureColorArray (pattern.width, pattern.height, pattern.GetPixels32 ());
        TextureColorArray dst = new TextureColorArray (textureWidth, textureHeight, newColors);

        foreach (IntVector2 point in points) {
            TextureUtil.applyTextureToAnotherTexture (ref src, ref dst, point);
        }
        return newColors;
    }