37 lines
1.0 KiB
C#
37 lines
1.0 KiB
C#
using DG.Tweening;
|
|
using System;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Assets.Scenes.Ride.Scripts
|
|
{
|
|
public class NumberDotween:MonoBehaviour
|
|
{
|
|
private Sequence mScoreSequence;
|
|
private Text text;
|
|
private float mOldScore = 0;
|
|
|
|
private void Start()
|
|
{
|
|
//函数内初始化
|
|
mScoreSequence = DOTween.Sequence();
|
|
//函数内设置属性
|
|
mScoreSequence.SetAutoKill(false);
|
|
text = transform.GetComponent<Text>();
|
|
}
|
|
|
|
public void AnimateNum(float newScore, int digit, string format)
|
|
{
|
|
mScoreSequence.Append(DOTween.To(delegate (float value)
|
|
{
|
|
var temp = Math.Round(value, digit);
|
|
//向Text组件赋值
|
|
text.text = string.Format(format, temp);
|
|
}, mOldScore, newScore, 1f));
|
|
//将更新后的值记录下来, 用于下一次滚动动画
|
|
mOldScore = newScore;
|
|
}
|
|
}
|
|
}
|