UnityEngine.ColorUtility.ToHtmlStringRGB C# (CSharp) Method

ToHtmlStringRGB() public static method

Returns the color as a hexadecimal string in the format "RRGGBB".

public static ToHtmlStringRGB ( Color color ) : string
color Color The color to be converted.
return string
        public static string ToHtmlStringRGB(Color color)
        {
            Color32 color2 = new Color32((byte) Mathf.Clamp(Mathf.RoundToInt(color.r * 255f), 0, 0xff), (byte) Mathf.Clamp(Mathf.RoundToInt(color.g * 255f), 0, 0xff), (byte) Mathf.Clamp(Mathf.RoundToInt(color.b * 255f), 0, 0xff), 1);
            return string.Format("{0:X2}{1:X2}{2:X2}", color2.r, color2.g, color2.b);
        }

Usage Example

コード例 #1
0
 public static string SetStringColor(string str, Color textColor)
 {
     return("<color=#" + ColorUtility.ToHtmlStringRGB(textColor) + ">" + str + "</color>");
 }