項目裡條件限制,隻能使用sprite renderer來做UI,原來做進度條效果都是用ngui或者ugui裡寫好的fill屬性。想到肯定可以用shader來實作,但是無奈自己并不會寫 T T 。找到個能用的shader,記錄下位址:
http://www.ceeger.com/forum/read.php?tid=3492;ds=1#tpc
感謝原作者。
shader的内容:
Shader "Custom/CursorLoadShader" {
Properties
{
_Color ("Main Color", Color) = (,,,)
_MainTex ("Base (RGB) Trans (A)", D) = "white" {}
_MaskTex ("Mask (A)", D) = "white" {}
_Progress ("Progress", Range(,)) =
}
Category
{
Lighting Off
ZWrite Off
Cull back
Fog { Mode Off }
Tags {"Queue"="Transparent" "IgnoreProjector"="True"}
Blend SrcAlpha OneMinusSrcAlpha
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
sampler2D _MaskTex;
fixed4 _Color;
float _Progress;
struct appdata
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert (appdata v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
return o;
}
half4 frag(v2f i) : COLOR
{
fixed4 c = _Color * tex2D(_MainTex, i.uv);
fixed ca = tex2D(_MaskTex, i.uv).a;
c.a *= ca >= _Progress ? : ;
return c;
}
ENDCG
}
}
SubShader
{
AlphaTest LEqual [_Progress]
Pass
{
SetTexture [_MaskTex] {combine texture}
SetTexture [_MainTex] {combine texture, previous}
}
}
}
Fallback "Transparent/VertexLit"
}
圓環形遮罩圖檔
