傳統按鈕置灰,需要使用另外一張紋理。
本例通過修改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即可!