DOTween.To(getter, setter, to, float duration) 是常用的一個變值方法(一定時間將某變數從起始值到終點值進行變化),可以便捷實作 滾分、漲進度條 等功能

但大部分用的時候都是基于 Linear 勻速曲線 進行變化的(因為沒刻意設定呀...),但也可以有緩動變化的情況,例如:

此類效果可以在Unity中配合DOTween.To()實作,不僅可以使用內置Ease曲線型別,還可以自定義AnimationCurve曲線實作
例如根據自定義AnimationCurve曲線實作的緩動滾分效果如下:


代碼實作
public static class NumberEffectUtility
{
public static void DoNumber(this Text numberText, int start, int end, float duration, Ease easeType = Ease.Linear)
{
DOTween.To(
() => start, //起始值
x =>
{
numberText.text = Mathf.Floor(x).ToString(); //變化值
},
end, //終點值
duration) //持續時間
.SetEase(easeType) //緩動型別
.SetUpdate(true); //不受Time.Scale影響
}
public static void DoNumber(this Text numberText, int start, int end, float duration, AnimationCurve animCurve)
{
DOTween.To(
() => start, //起始值
x =>
{
numberText.text = Mathf.Floor(x).ToString(); //變化值
},
end, //終點值
duration) //持續時間
.SetEase(animCurve) //緩動型別
.SetUpdate(true); //不受Time.Scale影響
}
}
參考文章
- 緩動函式
- DOTween
- Unity DoTween 影片使用案例
- 七何分析界面動效 - 錢程
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/403550.html
標籤:其他
下一篇:常見聚類演算法總結
