Example #1
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="texture">outLine Texture</param>
    /// <param name="persistentBorder">Border Texture</param>
    /// <param name="_fileFormat">file format : 0(psd or png (with alpha chanel)
    ///				1: JPEG (without alpha chanel))</param>
    public void setNewPicture(
        Texture2D texture,
        Texture2D persistentBorder = null,
        int _fileFormat            = 0
        )
    {
        //int totalPixelSize = config.canvasSize.x * config.canvasSize.y;
        int totalPixelSize = texture.width * texture.height;

        size = new Vector2(texture.width, texture.height);

        if (_actualColors == null || _actualColors.Length != (totalPixelSize))
        {
            _actualColors = new Color32[totalPixelSize];
        }

        ColorUtil.setWhitePixels(_actualColors);
        backLayer.setBlank(_actualColors);

        if (persistentBorder != null)
        {
            Color32[] colors = persistentBorder.GetPixels32();
            if (_persistentLayer == null ||
                _persistentLayer.Length != totalPixelSize)
            {
                _persistentLayer = new bool[totalPixelSize];
            }

            // adjust Texture's Color to be working
            // if the texture is JPEG or without alpha color's
            if (_fileFormat != 0)
            {
                for (int i = 0; i < _persistentLayer.Length; i++)
                {
                    if (colors[i].r >= 250 &&
                        colors[i].g >= 250 &&
                        colors[i].b >= 250)
                    {
                        colors[i].a = 0;
                    }
                    else
                    {
                        colors[i].r = 0;
                        colors[i].g = 0;
                        colors[i].b = 0;
                        colors[i].a = 255;
                    }
                }

                persistentBorder.SetPixels32(colors);
                persistentBorder.Apply();
            }

            if (texture != null)
            {
                frontLayer.setTexture(texture);
            }

            frontLayerNull = (texture == null);


            for (int i = 0; i < _persistentLayer.Length; i++)
            {
                _persistentLayer[i] = colors[i].a > 253;
            }
        }
        else
        {
            if (_persistentLayer == null ||
                _persistentLayer.Length != totalPixelSize)
            {
                _persistentLayer = new bool[totalPixelSize];
            }

            for (int i = 0; i < totalPixelSize; i++)
            {
                _persistentLayer[i] = false;
            }
        }

        undoRedoBuffer.resetUndoRedo();
    }