[原]NGUI之按钮置灰

传统按钮置灰,需要使用另外一张纹理。

本例通过修改shader和NGUI sprite的r值实现按钮置灰。优势:节省纹理,操作简单

将NGUI Unlit/Transparent Colored片段部分改成如下:
fixed4 frag (v2f i) : COLOR { fixed4 col
= tex2D(_MainTex, i.texcoord) * i.color; if(i.color.r < 0.0001) { float grey = dot(col.rgb, float3(0.299, 0.587, 0.114)); col.rgb = float3(grey, grey, grey); } return col; }
说明:其中(0.299,0.587,0.114)为灰度公式的参数

使用时仅需将sprite的颜色R值设置为0即可!

参考资料:NGUI之UIButton"禁用"状态时置灰

posted @ 2014-07-28 11:51  U_探索  阅读(3972)  评论(2编辑  收藏  举报