-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomMethods.cs
49 lines (41 loc) · 1.38 KB
/
CustomMethods.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
using Color = UnityEngine.Color;
namespace CrabGameUtils;
// ReSharper disable UnusedMember.Global
public static class CustomMethods
{
public static uint RandomColor() => (uint)new Random().Next(0x0, 0xFFFFFF);
public static float FixValue(float value, int min, int max)
{
if (value < min) return min;
if (value > max) return max;
return value;
}
public static Vector3 FillRandom(this Vector3 vector, int min, int max)
{
vector.x = UnityEngine.Random.Range(min, max);
vector.y = UnityEngine.Random.Range(min, max);
vector.z = UnityEngine.Random.Range(min, max);
return vector;
}
public static Color ToColor(this Vector3 vector)
=> new(vector.x, vector.y, vector.z);
public static void RandomColor(ref this Color color)
{
color = Color.HSVToRGB(UnityEngine.Random.Range(0, 255), 255, 255);
}
public static Texture MakeGrayscale (Texture2D tex , int skip)
{
var texColors = tex.GetPixels();
for (int i = 0; i < texColors.Length; i++)
{
if (i % skip == 0)
{
var grayValue = texColors[i].grayscale;
texColors[i] = new Color(grayValue, grayValue, grayValue, texColors[i].a);
}
}
tex.SetPixels(texColors);
tex.Apply();
return tex;
}
}