c# - Unity - 如何使用 Sprite 渲染器制作圆形进度条?

标签 c# unity-game-engine progress-bar sprite

到目前为止我所看到的,人们使用带有填充金额的 UI,这对我的 atm 来说不是一个选项。有谁知道如何使用 Sprite 渲染器制作圆形进度条?

最佳答案

我找到了一个不太优雅的解决方案,但可以完成工作。

如果您将 Sprite 切成两半(或仅使用 Sprite mask ),则可以使用旋转的 Sprite mask 来覆盖除您想要显示的百分比之外的所有内容。

using rotating a mask to cover parts of a circle.

然后您所要做的就是创建一个显示另一半的后半部分 Sprite 。

Two examples of a finished circular progress bar, one split in half and highlighted to show how it works.

这是我在上面的 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/

相关文章:

c# - unsigned char 到 char * 用于从 C++ WinSock 客户端到 C# 服务器的 TCP

flutter - 圆形进度指示器未居中 flutter

c# - 如何更改点光源内 'Draw Halo'的值-Unity3D

ruby - 用 ruby​​-progressbar gem 结束一个方法

android - 在对话框 fragment 上显示 ProgressBar

c# - Javascript函数无法到达其他函数?

c# - facebook open graph API 名称和命名空间属性

c# - .NET Core/EF Core 2.0 升级后急切加载 "No coercion operator is defined between types"

xcode - (Xcode) 命令phasescriptexecution 失败并出现非零执行错误(来自 EMPTY 2D iOS Unity 项目)

c# - 如何在我的统一创建的 android 应用程序中显示导航栏