forked from nathan-zaloum/BucketCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRGBColor.cs
50 lines (42 loc) · 1.24 KB
/
RGBColor.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
using UnityEngine;
namespace ColorConverter {
public class RGBColor {
public static Color RGBtoFloat (float r, float g, float b, float a) {
Color c;
// Check if any inputed values are greater than 255 and if they are then round them to 255.
if (r > 255.0f) {
r = 255.0f;
}
if (g > 255.0f) {
g = 255.0f;
}
if (b > 255.0f) {
b = 255.0f;
}
if (a > 255.0f) {
a = 255.0f;
}
// Check if any inputed values are less than 0 and if they are then round them to 0.
if (r < 0.0f) {
r = 0.0f;
}
if (g < 0.0f) {
g = 0.0f;
}
if (b < 0.0f) {
b = 0.0f;
}
if (a < 0.0f) {
a = 0.0f;
}
// Divide the values by 255 to get a decimal between 0 and 1.
r /= 255.0f;
g /= 255.0f;
b /= 255.0f;
a /= 255.0f;
// Combine all variables into a new Color and return that color.
c = new Color (r, g, b, a);
return c;
}
}
}