Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
ColorUtil.cs
Go to the documentation of this file.
1using UnityEngine;
2
3public class ColorUtil
4{
5 public static Color RandomHSV(float minS, float maxS, float minV, float maxV)
6 {
7 return HSVToRGB(Rand.Range(0f, 1f), Rand.Range(minS, maxS), Rand.Range(minV, maxV));
8 }
9
10 public static Color HSVToRGB(float H, float S, float V)
11 {
12 Color white = Color.white;
13 if (S == 0f)
14 {
15 white.r = V;
16 white.g = V;
17 white.b = V;
18 }
19 else if (V == 0f)
20 {
21 white.r = 0f;
22 white.g = 0f;
23 white.b = 0f;
24 }
25 else
26 {
27 white.r = 0f;
28 white.g = 0f;
29 white.b = 0f;
30 float num = H * 6f;
31 int num2 = (int)Mathf.Floor(num);
32 float num3 = num - (float)num2;
33 float num4 = V * (1f - S);
34 float num5 = V * (1f - S * num3);
35 float num6 = V * (1f - S * (1f - num3));
36 switch (num2)
37 {
38 case -1:
39 white.r = V;
40 white.g = num4;
41 white.b = num5;
42 break;
43 case 0:
44 white.r = V;
45 white.g = num6;
46 white.b = num4;
47 break;
48 case 1:
49 white.r = num5;
50 white.g = V;
51 white.b = num4;
52 break;
53 case 2:
54 white.r = num4;
55 white.g = V;
56 white.b = num6;
57 break;
58 case 3:
59 white.r = num4;
60 white.g = num5;
61 white.b = V;
62 break;
63 case 4:
64 white.r = num6;
65 white.g = num4;
66 white.b = V;
67 break;
68 case 5:
69 white.r = V;
70 white.g = num4;
71 white.b = num5;
72 break;
73 case 6:
74 white.r = V;
75 white.g = num6;
76 white.b = num4;
77 break;
78 }
79 white.r = Mathf.Clamp(white.r, 0f, 1f);
80 white.g = Mathf.Clamp(white.g, 0f, 1f);
81 white.b = Mathf.Clamp(white.b, 0f, 1f);
82 }
83 return white;
84 }
85}
static Color RandomHSV(float minS, float maxS, float minV, float maxV)
Definition: ColorUtil.cs:5
static Color HSVToRGB(float H, float S, float V)
Definition: ColorUtil.cs:10
Definition: Rand.cs:4
static int Range(int min, int max)
Definition: Rand.cs:42