直接上源码,需要的自取,通过更改X,Y来改变方向及速度
第一种:
Shader "UI/Flow UV" {
Properties{
_MainTex("Base (RGB)", 2D) = "white" {}
_MainTint("Diffuse Tint", Color) = (1, 1, 1, 1)
// 通过调整正负及值来改变方向与速度
_ScrollXSpeed("XSpeed", Range(-10, 50)) = -1
_ScrollYSpeed("YSpeed", Range(-10, 50)) = 15
}
SubShader{
Tags{ "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
float _ScrollXSpeed;
float _ScrollYSpeed;
fixed4 _MainTint;
struct Input {
float2 uv_MainTex;
};
void surf(Input IN, inout SurfaceOutput o)
{
fixed2 scrolledUV = IN.uv_MainTex;
fixed xScrollOffset = _ScrollXSpeed * _Time;
fixed yScrollOffset = _ScrollYSpeed * _Time;
scrolledUV += fixed2(xScrollOffset,yScrollOffset);
half4 c = tex2D(_MainTex, scrolledUV);
o.Albedo = c.rgb * _MainTint;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
第二种:
Shader "UI/MoveUV"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_SpeedX("SpeedX",Range(-4,4)) = 1
_SpeedY("SpeedY",Range(-4,4)) = 1
}
SubShader
{
Tags{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"PreviewType" = "Plane"
"CanUseSpriteAtlas" = "True"
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float _SpeedX;
float _SpeedY;
struct a2v {
float4 vertex:POSITION;
float4 texcoord:TEXCOORD;
};
struct v2f {
float4 pos:POSITION;
float4 uv:texcoord;
};
v2f vert(a2v v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord;
return o;
}
fixed4 frag(v2f i) :SV_Target{
//平移
fixed2 uv = i.uv;
uv = float2( uv.x - _Time.x * _SpeedX, uv.y - _Time.y * _SpeedY);
fixed4 c = tex2D(_MainTex, uv);
return c;
}
ENDCG
}
}
}