-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathColorExtension.cs
129 lines (117 loc) · 3.34 KB
/
ColorExtension.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//<author>Nicholas Irwin</author>
//<company> nonPareil Institute</company>
//<copyright file ="ColorExtension.cs" All Rights Reserved
//</copyright>
//<date>1/24/2018</date>
namespace npScripts
{
using UnityEngine;
/// <summary>
/// A set of extensions to the Color class.
/// </summary>
public static class ColorExtension
{
#region Methods
public static void ConvertColor(this Color c, int r, int g, int b, float a = 1f)
{
c.r = r / 255f;
c.g = g / 255f;
c.b =b /255f;
c.a = a;
}
/// <summary>
/// Returns an alphaed version of the given color.
/// </summary>
/// <param name="c">The <see cref="Color"/></param>
/// <param name="alpha">The <see cref="float"/></param>
/// <returns>The <see cref="Color"/></returns>
public static Color AlphaColor(Color c, float alpha)
{
Color cx = c;
cx.a = alpha;
return cx;
}
/// <summary>
/// Returns the color black with the given alpha.
/// </summary>
/// <param name="alpha">The <see cref="float"/></param>
/// <returns>The <see cref="Color"/></returns>
public static Color Black(float alpha)
{
return AlphaColor(Color.black, alpha);
}
/// <summary>
/// Returns the color blue with the given alpha.
/// </summary>
/// <param name="alpha">The <see cref="float"/></param>
/// <returns>The <see cref="Color"/></returns>
public static Color Blue(float alpha)
{
return AlphaColor(Color.blue, alpha);
}
/// <summary>
/// Returns the color cyan with the given alpha.
/// </summary>
/// <param name="alpha">The <see cref="float"/></param>
/// <returns>The <see cref="Color"/></returns>
public static Color Cyan(float alpha)
{
return AlphaColor(Color.cyan, alpha);
}
/// <summary>
/// Returns the color green with the given alpha.
/// </summary>
/// <param name="alpha">The <see cref="float"/></param>
/// <returns>The <see cref="Color"/></returns>
public static Color Green(float alpha)
{
return AlphaColor(Color.green, alpha);
}
/// <summary>
/// Returns the color orange. (51, 76.5, 102)
/// </summary>
/// <returns>The <see cref="Color"/></returns>
public static Color Orange()
{
Color color = new Color(0.2F, 0.3F, 0.4F);
return color;
}
/// <summary>
/// Returns the color orange with the given alpha. (51, 76.5, 102)
/// </summary>
/// <param name="alpha">The <see cref="float"/></param>
/// <returns>The <see cref="Color"/></returns>
public static Color Orange(float alpha)
{
return AlphaColor(ColorExtension.Orange(), alpha);
}
/// <summary>
/// Returns the color red with the given alpha.
/// </summary>
/// <param name="alpha">The <see cref="float"/></param>
/// <returns>The <see cref="Color"/></returns>
public static Color Red(float alpha)
{
return AlphaColor(Color.red, alpha);
}
/// <summary>
/// Returns the color white with the given alpha.
/// </summary>
/// <param name="alpha">The <see cref="float"/></param>
/// <returns>The <see cref="Color"/></returns>
public static Color White(float alpha)
{
return AlphaColor(Color.white, alpha);
}
/// <summary>
/// Returns the color yellow with the given alpha.
/// </summary>
/// <param name="alpha">The <see cref="float"/></param>
/// <returns>The <see cref="Color"/></returns>
public static Color Yellow(float alpha)
{
return AlphaColor(Color.yellow, alpha);
}
#endregion
}
}