到目前为止我所看到的,人们使用带有填充金额的 UI,这对我的 atm 来说不是一个选项。有谁知道如何使用 Sprite 渲染器制作圆形进度条?
最佳答案
我找到了一个不太优雅的解决方案,但可以完成工作。
如果您将 Sprite 切成两半(或仅使用 Sprite mask ),则可以使用旋转的 Sprite mask 来覆盖除您想要显示的百分比之外的所有内容。
using rotating a mask to cover parts of a circle.
然后您所要做的就是创建一个显示另一半的后半部分 Sprite 。
这是我在上面的 gif 中使用的代码:
public class CircularFillBar : MonoBehaviour
{
public float FillValue;
private Transform TopHideBar;
private Transform BottomHideBar;
void Start()
{
TopHideBar = transform.Find("CircularFillBar (Top)").Find("Rotation Container (moving)");
BottomHideBar = transform.Find("CircularFillBar (Bottom)").Find("Rotation Container (moving)");
}
private void FixedUpdate()
{
TopHideBar.rotation = Quaternion.Euler(0, 0, (FillValue * 360 > 180 ? 180 : FillValue * 360));
BottomHideBar.rotation = Quaternion.Euler(0, 0, (FillValue * 360 < 180 ? 180 : FillValue * 360));
FillValue += 0.002f;
if (FillValue > 1)
FillValue = 0;
}
}
关于c# - Unity - 如何使用 Sprite 渲染器制作圆形进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61168171/