使用两个静态方法,代码如下:
public class Utilities
{
public static Color GetRGBAColor(string strColor)
{
var color = Convert.ToUInt32(strColor, 16);
return new Color((color >> 24 & 0xFF) / 255f, (color >> 16 & 0xFF) / 255f,
(color >> 8 & 0xFF) / 255f, (color & 0xFF) / 255f);
}
public static string ColorToRGBAString(Color color)
{
int r = Mathf.RoundToInt(color.r * 255);
int g = Mathf.RoundToInt(color.g * 255);
int b = Mathf.RoundToInt(color.b * 255);
int a = Mathf.RoundToInt(color.a * 255);
uint rgba = (uint)(r << 24 | g << 16 | b << 8 | a);
return rgba.ToString("X8");
}
}