输出十进制色值
Color nowColor;
ColorUtility.TryParseHtmlString("#FECEE1", out nowColor);
ColorUtility.ToHtmlStringRGB:传入的是一个Color结构体,返回一个字符串,形式是“FFFFFF”,用法如下:
input16Color.text = ColorUtility.ToHtmlStringRGB(nowColor);
传入str格式""FFFFFF""
Color converToColor(string str)
{
float aa = convertColor(str).a / 255;
float rr = convertColor(str).r / 255;
float gg = convertColor(str).g / 255;
float bb = convertColor(str).b / 255;
return new Color(rr, gg, bb, aa);
}
private Color convertColor(string colorString)//16进制颜色值
{
int v = int.Parse(colorString, System.Globalization.NumberStyles.HexNumber);
return new Color()
{
//a = Convert.ToByte((v >> 24) & 255),
a = 255,
r = Convert.ToByte((v >> 16) & 255),
g = Convert.ToByte((v >> 8) & 255),
b = Convert.ToByte((v >> 0) & 255)
};
}