深圳网站制作排行榜,制作一个私人网站怎么申请域名,提高百度搜索排名,传播学视角下网站建设研究不做UI不知道#xff0c;没想到时至今日#xff0c;ugui居然没有sliced filled image模式#xff0c;用circle做filled#xff0c;不能用sliced九宫格图#xff0c;导致每次使用这个效果必须一张新图#xff0c;何其浪费资源。 原始功能如下#xff1a; 我… 不做UI不知道没想到时至今日ugui居然没有sliced filled image模式用circle做filled不能用sliced九宫格图导致每次使用这个效果必须一张新图何其浪费资源。 原始功能如下 我觉得还是自己写shader解决这个问题比较方便原理很简单通过frag函数逐uv扫描中心pixel坐标与uv pixel坐标的朝向向量与轴向量比如up direction的夹角从0-360度限制discard像素即可。 唯一注意事项就是夹角的正负值计算问题这里我们用叉积判断正负值即可unity右手坐标系扩展z轴 直接上代码
Shader UI360FilledAndSliced/UI360FilledUnlitShader
{Properties{_MainTex (Texture, 2D) white {}_Axis(Axis,vector) (0,0.5,0,0)_Degree(Degree,Range(0,360)) 0}SubShader{Tags { RenderTypeTransparent QueueTransparent }LOD 100Pass{Blend SrcAlpha OneMinusSrcAlphaCGPROGRAM#pragma vertex vert#pragma fragment frag#define RAD2DEG 57.29578#include UnityCG.cgincstruct appdata{float4 vertex : POSITION;float2 uv : TEXCOORD0;};struct v2f{float2 uv : TEXCOORD0;float4 vertex : SV_POSITION;};sampler2D _MainTex;float4 _MainTex_ST;float2 _Axis;float _Degree;v2f vert (appdata v){v2f o;o.vertex UnityObjectToClipPos(v.vertex);o.uv TRANSFORM_TEX(v.uv, _MainTex);return o;}//unity右手坐标系//获取夹角正负值//左手定则float getClampPM(float2 f,float2 t){float3 f3 float3(f,0);float3 t3 float3(t,0);float3 n3 cross(f3,t3);return n3.z;}//计算夹角//左手定则float getClampDegree(float2 f,float2 t){float cos dot(f,t)/(length(f)*length(t));float deg acos(cos)*RAD2DEG;float pm getClampPM(f,t);if(pm0){deg 360-abs(deg);}return deg;}fixed4 frag (v2f i) : SV_Target{fixed4 col tex2D(_MainTex, i.uv);float2 cuv float2(0.5,0.5);float2 p2c i.uv-cuv;float deg getClampDegree(_Axis,p2c);if(deg_Degree){discard;}return col;}ENDCG}}
}效果如下 后面我试了下最新的unity版本ugui有一样的问题可见unity还需要持续完善。