Exemplo n.º 1
0
        public static Color4 BlendFunc(Color4 source, Color4 destination, ColorBlendMode mode)
        {
            switch (mode)
            {
                case ColorBlendMode.Zero:
                    return new Color4(0.0f, 0.0f, 0.0f, 0.0f);
                case ColorBlendMode.One:
                    return new Color4(1.0f, 1.0f, 1.0f, 1.0f);
                case ColorBlendMode.SourceColor:
                    return new Color4(source.R, source.G, source.B, source.A);
                case ColorBlendMode.InverseSourceColor:
                    return new Color4(1 - source.R, 1 - source.G, 1 - source.B, 1 - source.A);
                case ColorBlendMode.SourceAlpha:
                    return new Color4(source.A, source.A, source.A, source.A);
                case ColorBlendMode.InverseSourceAlpha:
                    return new Color4(1 - source.A, 1 - source.A, 1 - source.A, 1 - source.A);
                case ColorBlendMode.DestinationAlpha:
                    return new Color4(destination.A, destination.A, destination.A, destination.A);
                case ColorBlendMode.InverseDestinationAlpha:
                    return new Color4(1 - destination.A, 1 - destination.A, 1 - destination.A, 1 - destination.A);
                case ColorBlendMode.DestinationColor:
                    return new Color4(destination.R, destination.G, destination.B, destination.A);
                case ColorBlendMode.InverseDestinationColor:
                    return new Color4(1 - destination.R, 1 - destination.G, 1 - destination.B, 1 - destination.A);
                case ColorBlendMode.SourceAlphaSaturation:
                    return new Color4(Math.Min(source.A, 1 - source.A), Math.Min(source.A, 1 - source.A),
                                      Math.Min(source.A, 1 - source.A), 1);
            }

            throw new Exception();
        }
Exemplo n.º 2
0
        public override void Reset()
        {
            base.Reset();

            fromOffsetBlendMode = ColorBlendMode.Normal;
            toOffsetBlendMode   = ColorBlendMode.Normal;

            gameObject       = null;
            cachedGameObject = null;
            cachedComponent  = null;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Common blend operations for colors
        /// E.g. used by TweenColor action
        /// </summary>
        /// <returns></returns>
        public static Color BlendColor(ColorBlendMode blendMode, Color c1, Color c2)
        {
            switch (blendMode)
            {
            case ColorBlendMode.Normal:
                return(Color.Lerp(c1, c2, c2.a));

            case ColorBlendMode.Multiply:
                return(Color.Lerp(c1, c1 * c2, c2.a));

            case ColorBlendMode.Screen:
                var screen = Color.white - (Color.white - c1) * (Color.white - c2);
                return(Color.Lerp(c1, screen, c2.a));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 4
0
        public static Color4 BlendFunc(Color4 source, Color4 destination, ColorBlendMode mode)
        {
            switch (mode)
            {
            case ColorBlendMode.Zero:
                return(new Color4(0.0f, 0.0f, 0.0f, 0.0f));

            case ColorBlendMode.One:
                return(new Color4(1.0f, 1.0f, 1.0f, 1.0f));

            case ColorBlendMode.SourceColor:
                return(new Color4(source.R, source.G, source.B, source.A));

            case ColorBlendMode.InverseSourceColor:
                return(new Color4(1 - source.R, 1 - source.G, 1 - source.B, 1 - source.A));

            case ColorBlendMode.SourceAlpha:
                return(new Color4(source.A, source.A, source.A, source.A));

            case ColorBlendMode.InverseSourceAlpha:
                return(new Color4(1 - source.A, 1 - source.A, 1 - source.A, 1 - source.A));

            case ColorBlendMode.DestinationAlpha:
                return(new Color4(destination.A, destination.A, destination.A, destination.A));

            case ColorBlendMode.InverseDestinationAlpha:
                return(new Color4(1 - destination.A, 1 - destination.A, 1 - destination.A, 1 - destination.A));

            case ColorBlendMode.DestinationColor:
                return(new Color4(destination.R, destination.G, destination.B, destination.A));

            case ColorBlendMode.InverseDestinationColor:
                return(new Color4(1 - destination.R, 1 - destination.G, 1 - destination.B, 1 - destination.A));

            case ColorBlendMode.SourceAlphaSaturation:
                return(new Color4(Math.Min(source.A, 1 - source.A), Math.Min(source.A, 1 - source.A),
                                  Math.Min(source.A, 1 - source.A), 1));
            }

            throw new Exception();
        }
Exemplo n.º 5
0
    public static void ColorToolsWindow()
    {
        Color lastColor = GUI.contentColor;

        GUILayout.BeginVertical();

        // Channels
        {
            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Channel Mask");
            GUIContent[] contents = new GUIContent[] {
                new GUIContent("All", "All Channels"),
                new GUIContent("R", "Red"),
                new GUIContent("G", "Green"),
                new GUIContent("B", "Blue")
            };
            ColorChannelsMode temp = (ColorChannelsMode)GUILayout.Toolbar((int)colorChannelsMode, contents, toolbarButtonStyle);
            if (temp != colorChannelsMode)
            {
                newColorChannelsMode = temp;
            }
            GUILayout.EndHorizontal();
        }

        // Color
        if (colorChannelsMode == ColorChannelsMode.AllChannels)
        {
            colorBrushColor = EditorGUILayout.ColorField("Color", colorBrushColor);
        }

        // Blend
        {
            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Mode");
            GUIContent[] contents = new GUIContent[] {
                new GUIContent(tk2dEditorSkin.GetTexture("icon_pencil"), "Replace"),
                new GUIContent("+", "Addition"),
                new GUIContent("-", "Subtraction"),
                new GUIContent(tk2dEditorSkin.GetTexture("icon_eyedropper"), "Eyedropper")
            };
            colorBlendMode = (ColorBlendMode)GUILayout.Toolbar((int)colorBlendMode, contents, toolbarButtonStyle);
            GUILayout.EndHorizontal();
        }

        // Radius, Intensity
        {
            GUIContent radiusLabel = new GUIContent("Radius", "Shortcut - [, ]");
            colorBrushRadius = EditorGUILayout.Slider(radiusLabel, colorBrushRadius, 1.0f, 64.0f);

            GUIContent intensityLabel = new GUIContent("Intensity", "Shortcut - Minus (-), Plus (+)");
            colorBrushIntensity = EditorGUILayout.Slider(intensityLabel, colorBrushIntensity * 100.0f, 0.0f, 100.0f) / 100.0f;
        }

        // Curve
        {
            colorBrushCurve = EditorGUILayout.CurveField("Brush shape", colorBrushCurve);
        }

        GUILayout.EndVertical();

        GUI.contentColor = lastColor;

        if (Event.current.type == EventType.Repaint)
        {
            colorChannelsMode = newColorChannelsMode;
            HandleUtility.Repaint();
        }
    }
Exemplo n.º 6
0
        /// <summary>
        /// Blend color a and color b.
        /// </summary>
        /// <param name="a">Color a.</param>
        /// <param name="b">Color b.</param>
        /// <param name="mode">Mode of color blend.</param>
        /// <returns>Blended color.</returns>
        public static Color Blend(Color a, Color b, ColorBlendMode mode)
        {
            var c = Color.white;

            switch (mode)
            {
            case ColorBlendMode.Normal:
                c = NormalBlend(a, b);
                break;

            case ColorBlendMode.Dissolve:
                c = DissolveBlend(a, b);
                break;

            case ColorBlendMode.Darken:
                c = DarkenBlend(a, b);
                break;

            case ColorBlendMode.Multiply:
                c = MultiplyBlend(a, b);
                break;

            case ColorBlendMode.ColorBurn:
                c = ColorBurnBlend(a, b);
                break;

            case ColorBlendMode.LinearBurn:
                c = LinearBurnBlend(a, b);
                break;

            case ColorBlendMode.DarkerColor:
                c = DarkerColorBlend(a, b);
                break;

            case ColorBlendMode.Lighten:
                c = LightenBlend(a, b);
                break;

            case ColorBlendMode.Screen:
                c = ScreenBlend(a, b);
                break;

            case ColorBlendMode.ColorDodge:
                c = ColorDodgeBlend(a, b);
                break;

            case ColorBlendMode.LinearDodge:
                c = LinearDodgeBlend(a, b);
                break;

            case ColorBlendMode.LighterColor:
                c = LighterColorBlend(a, b);
                break;

            case ColorBlendMode.Overlay:
                c = OverlayBlend(a, b);
                break;

            case ColorBlendMode.SoftLight:
                c = SoftLightBlend(a, b);
                break;

            case ColorBlendMode.HardLight:
                c = HardLightBlend(a, b);
                break;

            case ColorBlendMode.VividLight:
                c = VividLightBlend(a, b);
                break;

            case ColorBlendMode.LinearLight:
                c = LinearLightBlend(a, b);
                break;

            case ColorBlendMode.PinLight:
                c = PinLightBlend(a, b);
                break;

            case ColorBlendMode.HardMix:
                c = HardMixBlend(a, b);
                break;

            case ColorBlendMode.Difference:
                c = DifferenceBlend(a, b);
                break;

            case ColorBlendMode.Exclusion:
                c = ExclusionBlend(a, b);
                break;

            case ColorBlendMode.Subtract:
                c = SubtractBlend(a, b);
                break;

            case ColorBlendMode.Divide:
                c = DivideBlend(a, b);
                break;

            case ColorBlendMode.Hue:
                c = HueBlend(a, b);
                break;

            case ColorBlendMode.Color:
                c = ColorBlend(a, b);
                break;

            case ColorBlendMode.Saturation:
                c = SaturationBlend(a, b);
                break;

            case ColorBlendMode.Luminosity:
                c = LuminosityBlend(a, b);
                break;
            }
            return(c);
        }
Exemplo n.º 7
0
	public static void ColorToolsWindow() {
		Color lastColor = GUI.contentColor;

		GUILayout.BeginVertical();

		// Channels
		{
			GUILayout.BeginHorizontal();
			EditorGUILayout.PrefixLabel("Channel Mask");
			GUIContent[] contents = new GUIContent[] {
				new GUIContent("All", "All Channels"),
				new GUIContent("R", "Red"),
				new GUIContent("G", "Green"),
				new GUIContent("B", "Blue")
			};
			ColorChannelsMode temp = (ColorChannelsMode)GUILayout.Toolbar((int)colorChannelsMode, contents, toolbarButtonStyle);
			if (temp != colorChannelsMode)
				newColorChannelsMode = temp;
			GUILayout.EndHorizontal();
		}

		// Color
		if (colorChannelsMode == ColorChannelsMode.AllChannels) {
			colorBrushColor = EditorGUILayout.ColorField("Color", colorBrushColor);
		}

		// Blend
		{
			GUILayout.BeginHorizontal();
			EditorGUILayout.PrefixLabel("Mode");
			GUIContent[] contents = new GUIContent[] {
				new GUIContent(tk2dEditorSkin.GetTexture("icon_pencil"), "Replace"),
				new GUIContent("+", "Addition"),
				new GUIContent("-", "Subtraction"),
				new GUIContent(tk2dEditorSkin.GetTexture("icon_eyedropper"), "Eyedropper")
			};
			colorBlendMode = (ColorBlendMode)GUILayout.Toolbar((int)colorBlendMode, contents, toolbarButtonStyle);
			GUILayout.EndHorizontal();
		}

		// Radius, Intensity
		{
			GUIContent radiusLabel = new GUIContent("Radius", "Shortcut - [, ]");
			colorBrushRadius = EditorGUILayout.Slider(radiusLabel, colorBrushRadius, 1.0f, 64.0f);

			GUIContent intensityLabel = new GUIContent("Intensity", "Shortcut - Minus (-), Plus (+)");
			colorBrushIntensity = EditorGUILayout.Slider(intensityLabel, colorBrushIntensity * 100.0f, 0.0f, 100.0f) / 100.0f;
		}

		// Curve
		{
			colorBrushCurve = EditorGUILayout.CurveField("Brush shape", colorBrushCurve);
		}

		GUILayout.EndVertical();

		GUI.contentColor = lastColor;

		if (Event.current.type == EventType.Repaint) {
			colorChannelsMode = newColorChannelsMode;
			HandleUtility.Repaint();
		}
	}
Exemplo n.º 8
0
 public static Color4 Add(Color4 source, ColorBlendMode sourceMode, Color4 destination, ColorBlendMode destMode)
 {
     return(AddColors(MultiplyColors(source, BlendFunc(source, destination, sourceMode)),
                      MultiplyColors(destination, BlendFunc(source, destination, destMode))));
 }
Exemplo n.º 9
0
 public static Color4 Add(Color4 source, ColorBlendMode sourceMode, Color4 destination, ColorBlendMode destMode)
 {
     return AddColors(MultiplyColors(source, BlendFunc(source, destination, sourceMode)),
                      MultiplyColors(destination, BlendFunc(source, destination, destMode)));
 }