最佳答案
我会使用自定义着色器和一个包含“填充信息”的 Sprite 作为 alpha channel 。
在下图中,您将看到您的原始 Sprite 和另一个具有渐变 alpha 的 Sprite (抱歉,我不是 Photoshop 专家)。
您可以在 their website 上下载 Unity 着色器。 ,然后选择 DefaultResourcesExtra/UI 中的 UI-Default.shader 并稍微调整一下,以便根据 Sprite 的 alpha 值填充 Sprite 。
类似这样的(未测试)
Shader "UI/FillAlpha"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_FillAmount ("Fill amount", Float) = 1
// ...
}
SubShader
{
// ...
sampler2D _MainTex;
fixed _FillAmount;
fixed4 frag(v2f IN) : SV_Target
{
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
color.a = color.a > _FillAmount ? 1 : 0 ;
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
// ...
return color;
}
ENDCG
}
}
}
然后,您将能够使用 myMaterial.SetFloat
更改 FillAmount
参数
关于user-interface - 在 Unity 中创建一个螺旋形 UI 栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48073418/