Esempio n. 1
0
    // Calculates the blended image given a list of layers
    public static Texture2D CalculateBlendedTex(List <UPALayer> _layers, UPALayer.BlendMode mode = UPALayer.BlendMode.NULL)
    {
        if (_layers.Count > 0)
        {
            // Calculate blended image
            Texture2D _result = null;
            for (int i = 0; i < _layers.Count; i++)
            {
                UPALayer.BlendMode tempMode;
                if (mode == UPALayer.BlendMode.NULL)
                {
                    tempMode = _layers[i].mode;
                }
                else
                {
                    tempMode = mode;
                }
                if (!_layers[i].enabled)
                {
                    continue;
                }

                if (_result == null)
                {
                    _result = UPABlendModes.Blend(_layers[i].tex, _layers[i].opacity, _layers[i].tex, _layers[i].opacity, tempMode);
                }
                else
                {
                    _result = UPABlendModes.Blend(_result, 1, _layers[i].tex, _layers[i].opacity, tempMode);
                }
            }
            if (_result == null)
            {
                Texture2D _empty = new Texture2D(1, 1);
                _empty.SetPixel(0, 0, Color.clear);
                _empty.Apply();
                return(_empty);
            }
            return(_result);
        }
        else
        {
            Texture2D _empty = new Texture2D(1, 1);
            _empty.SetPixel(0, 0, Color.clear);
            _empty.Apply();
            return(_empty);
        }
    }
        public static Texture2D Blend(Texture2D lowerLayer, float lowerOpacity, Texture2D upperLayer, float upperOpacity, UPALayer.BlendMode mode)
        {
            switch (mode)
            {
            case UPALayer.BlendMode.NORMAL:
                return(Normal(lowerLayer, lowerOpacity, upperLayer, upperOpacity));

            case UPALayer.BlendMode.MULTIPLY:
                return(Multiply(lowerLayer, lowerOpacity, upperLayer, upperOpacity));

            case UPALayer.BlendMode.SCREEN:
                return(Screen(lowerLayer, lowerOpacity, upperLayer, upperOpacity));

            case UPALayer.BlendMode.NOALPHA:
                return(NoAlpha(lowerLayer, lowerOpacity, upperLayer, upperOpacity));

            default:
                return(Normal(lowerLayer, lowerOpacity, upperLayer, upperOpacity));
            }
        }