DragonECS-Unity/src/Internal/Utils/ColorUtility.cs

20 lines
611 B
C#
Raw Normal View History

2024-03-05 00:46:47 +08:00
using UnityEngine;
namespace DCFApixels.DragonECS.Unity.Internal
{
internal static class ColorUtility
{
public static Color Desaturate(this Color self, float t)
{
float r = self.r;
float g = self.g;
float b = self.b;
//float gray = r * 0.299f + g * 0.587f + b * 0.114f;
float gray = r * 0.3333333f + g * 0.3333333f + b * 0.3333333f;
r = r + (gray - r) * (1 - t);
g = g + (gray - g) * (1 - t);
b = b + (gray - b) * (1 - t);
2024-03-10 08:10:58 +08:00
return new Color(r, g, b, self.a);
2024-03-05 00:46:47 +08:00
}
}
}