<pre name="code" class="plain">
Unlit/Transparent Colored
struct v2f
{
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
fixed4 color : COLOR;
fixed gray : TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
o.color = v.color;
o.gray = dot(v.color, fixed4(1,1,1,0));
return o;
}
fixed4 frag (v2f i) : COLOR
{
fixed4 col;
if (i.gray == 0)
{
col = tex2D(_MainTex, i.texcoord);
col.rgb = dot(col.rgb, fixed3(.222,.707,.071));
}
else
{
col = tex2D(_MainTex, i.texcoord) * i.color;
}
return col;
}
设置UISprite.color = Color.black;使图片黑白