找回密码
 立即注册
查看: 256|回复: 0

Unity Color RGB Lua 转16进制

[复制链接]
发表于 2022-7-12 11:31 | 显示全部楼层 |阅读模式
local function converRGB2Hex(r, g, b)    local str = ""    --十进制转到十六进制    if string.len(string.sub(string.format("%#x",r),3)) == 1 then        str = str .. "0" .. string.sub(string.format("%#x",r),3)    elseif string.len(string.sub(string.format("%#x",r),3)) == 0 then        str = str .. "00"    else        str = str .. string.sub(string.format("%#x",r),3)    end        if string.len(string.sub(string.format("%#x",g),3)) == 1 then        str = str .. "0" .. string.sub(string.format("%#x",g),3)    elseif string.len(string.sub(string.format("%#x",g),3)) == 0 then        str = str .. "00"    else        str = str .. string.sub(string.format("%#x",g),3)    end    if string.len(string.sub(string.format("%#x",b),3)) == 1 then        str = str .. "0" .. string.sub(string.format("%#x",b),3)    elseif string.len(string.sub(string.format("%#x",b),3)) == 0 then        str = str .. "00"    else        str = str .. string.sub(string.format("%#x",b),3)    end    return strendlocal function converColor2Hex(color)    return converRGB2Hex(color.r, color.g, color.b)end
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-19 00:49 , Processed in 0.088809 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表