NGUI是强大的插件,但是在UI设计中,很多时候设计者把不可点击的按钮或者图片希望用灰白颜色表示,遗憾的NGUI没有直接提供这样的功能,但是可以通过修改NGUI的几个shader达到这样的效果,我们指定一旦把组件的颜色设置为黑色时,就是默认变灰的效果。以下代码是Shader "Unlit/Transparent
Colored"的片段函数修改方法。类似的Transparent Colored的其他几个shader也可以如此修改。如果大家还要更好的方案欢迎讨论。
fixed4 frag (v2f i) : COLOR
{
fixed4 col;
if(i.color.r < 0.01 && i.color.g < 0.01 && i.color.b < 0.01 )
{
col = tex2D(_MainTex, i.texcoord);
float grey = dot(col.rgb, float3(0.299, 0.587, 0.114));
col.rgb = float3(grey, grey, grey);
}
else
{
col = tex2D(_MainTex, i.texcoord)* i.color;
}
return col;
}
fixed4 frag (v2f i) : COLOR
{
fixed4 col;
if(i.color.r < 0.01 && i.color.g < 0.01 && i.color.b < 0.01 )
{
col = tex2D(_MainTex, i.texcoord);
float grey = dot(col.rgb, float3(0.299, 0.587, 0.114));
col.rgb = float3(grey, grey, grey);
}
else
{
col = tex2D(_MainTex, i.texcoord)* i.color;
}
return col;
}
本文介绍如何通过修改NGUI的shader代码,实现在UI设计中将不可点击的按钮或图片变为灰色显示的方法,包括具体代码实现和相关shader片段函数的修改。
1002

被折叠的 条评论
为什么被折叠?



