Skip to content

Commit afa744a

Browse files
committed
Add color extension utility functions
1 parent fbbab11 commit afa744a

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

Runtime/ColorExtensions.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using UnityEngine;
2+
3+
namespace Zigurous.Tweening
4+
{
5+
/// <summary>
6+
/// Utility extension methods for colors.
7+
/// </summary>
8+
internal static class ColorExtensions
9+
{
10+
/// <summary>
11+
/// Returns a copy of the color with the red component changed.
12+
/// </summary>
13+
/// <param name="color">The color to change.</param>
14+
/// <param name="red">The new red component.</param>
15+
/// <returns>A copy of the color with the red component changed.</returns>
16+
public static Color WithRed(this Color color, float red)
17+
{
18+
return new Color(red, color.g, color.b, color.a);
19+
}
20+
21+
/// <summary>
22+
/// Returns a copy of the color with the green component changed.
23+
/// </summary>
24+
/// <param name="color">The color to change.</param>
25+
/// <param name="green">The new green component.</param>
26+
/// <returns>A copy of the color with the green component changed.</returns>
27+
public static Color WithGreen(this Color color, float green)
28+
{
29+
return new Color(color.r, green, color.b, color.a);
30+
}
31+
32+
/// <summary>
33+
/// Returns a copy of the color with the blue component changed.
34+
/// </summary>
35+
/// <param name="color">The color to change.</param>
36+
/// <param name="blue">The new blue component.</param>
37+
/// <returns>A copy of the color with the blue component changed.</returns>
38+
public static Color WithBlue(this Color color, float blue)
39+
{
40+
return new Color(color.r, color.g, blue, color.a);
41+
}
42+
43+
/// <summary>
44+
/// Returns a copy of the color with the alpha component changed.
45+
/// </summary>
46+
/// <param name="color">The color to change.</param>
47+
/// <param name="alpha">The new alpha component.</param>
48+
/// <returns>A copy of the color with the alpha component changed.</returns>
49+
public static Color WithAlpha(this Color color, float alpha)
50+
{
51+
return new Color(color.r, color.g, color.b, alpha);
52+
}
53+
54+
}
55+
56+
}

Runtime/ColorExtensions.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)