UnityEngine下的ColorUtility

本文介绍了一个实用的颜色转换工具ColorUtility,该工具包含将颜色转换为HTML格式的十六进制字符串的功能,支持RGB和RGBA模式,并提供了从十六进制字符串解析颜色的方法。通过示例展示了如何使用此工具改变背景颜色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 public class ColorUtility
    {
        public ColorUtility();

        //
        // 摘要:
        //     Returns the color as a hexadecimal string in the format "RRGGBB".
        //
        // 参数:
        //   color:
        //     The color to be converted.
        //
        // 返回结果:
        //     Hexadecimal string representing the color.
        public static string ToHtmlStringRGB(Color color);//通过颜色转化为十六进制
        //
        // 摘要:
        //     Returns the color as a hexadecimal string in the format "RRGGBBAA".
        //
        // 参数:
        //   color:
        //     The color to be converted.
        //
        // 返回结果:
        //     Hexadecimal string representing the color.
        public static string ToHtmlStringRGBA(Color color);//R:red红色,G:green蓝色,B:Blue绿色,A代表透明度,(0,0,0)黑,(255,255,255)白,三色的颜色值一样为灰色
        public static bool TryParseHtmlString(string htmlString, out Color color);//把十六进制转化为颜色并输出到color
    }

改变背景的颜色

 ColorUtility.TryParseHtmlString("#CCEEFFFF", out tempColor);//将16位解析输出到颜色对象
 bgImage.color = tempColor;//设置背景的颜色
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值