进度条shader 如下,创建三层Ui,第一层是外层蓝色,里层是那一个半透明的层,中间是那个绿色进度条添加下面的shader 的材质。通过外部设置shader “_Angle” 参数的改变来控制进度条。
Shader "UIEffect/uGUI_rand360"{ PRoperties { [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} _Color ("Tint", Color) = (1,1,1,1) _Angle ("Angle", float) = 360 _Center ("Center", vector) = (.5,.5,0,0) _Width ("Width", float) = 1 _AngleOffset("AngleOffset", float) = 0 [Toggle(CLOCK_WISE)]_ClockWise("ClockWise", float) = 1 _StencilComp ("Stencil Comparison", Float) = 8 _Stencil ("Stencil ID", Float) = 0 _StencilOp ("Stencil Operation", Float) = 0 _StencilWriteMask ("Stencil Write Mask", Float) = 255 _StencilReadMask ("Stencil Read Mask", Float) = 255 _ColorMask ("Color Mask", Float) = 15 } SubShader { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" } Stencil { Ref [_Stencil] Comp [_StencilComp] Pass [_StencilOp] ReadMask [_StencilReadMask] WriteMask [_StencilWriteMask] } Cull Off Lighting Off ZWrite Off ZTest [unity_GUIZTestMode] Blend SrcAlpha OneMinusSrcAlpha ColorMask [_ColorMask] Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma shader_feature CLOCK_WISE #include "UnityCG.cginc" #include "UnityUI.cginc" float _Angle; float4 _Center; float _AngleOffset; half _Width; struct appdata_t { float4 vertex : POSITION; float4 color : COLOR; float2 texcoord : TEXCOORD0; }; struct v2f { float4 vertex : SV_POSITION; fixed4 color : COLOR; half2 texcoord : TEXCOORD0; float4 worldPosition : TEXCOORD1; }; fixed4 _Color; fixed4 _TextureSampleAdd; bool _UseClipRect; float4 _ClipRect; bool _UseAlphaClip; v2f vert(appdata_t IN) { v2f OUT; OUT.worldPosition = IN.vertex; OUT.vertex = mul(UNITY_MATRIX_MVP, OUT.worldPosition); OUT.texcoord = IN.texcoord; #ifdef UNITY_HALF_TEXEL_OFFSET OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1); #endif OUT.color = IN.color * _Color; return OUT; } sampler2D _MainTex; fixed4 frag(v2f IN) : SV_Target { half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color; float2 pos = IN.texcoord.xy - _Center.xy; float x = pos.x; #ifdef CLOCK_WISE x = -x; #endif //float ang = degrees(atan2(x, -pos.y)) + 180; float ang = degrees(atan2(x, -pos.y)) + 180; color.a = color.a * saturate((ang - _Angle )/_Width); return color; } ENDCG } } FallBack "Custom/Color Texture" }新闻热点
疑难解答