unity3dDOTween动画实现数字变化动画
在游戏中,经常有这样的需要数字从1逐步增加到⼀个值N,⽽动画由1到这个值N的变化过程中,每变化⼀次,都是有动画,但是往往这个动画还没结束,下个动画就来了。想解决这个问题,可以使⽤下⾯这个思路。
即这个动画没播完之前,下个动画不能播,播完⼀个动画后,再进⾏下⼀个。下⾯请看代码。
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using DG.Tweening;
public class InGameFlowerItem : MonoBehaviour
{
public uint m_ID;
public string m_SenderName = "";
public int m_Num = 0;//已经送花的数量
public Text m_NameText;
public Text m_NumText;
public float m_RemoveTime = 5f;
Tweener m_Tweener;
private int m_tweenNum = 0;
private bool flag = false;
public void Show()
{
gameObject.SetActive(true);
= m_SenderName;
if (m_Num <= 5)
{
= m_Num.ToString();
}
this.Invoke("RemoveSelf", m_RemoveTime);
}
public void AddNum()
{
this.CancelInvoke("RemoveSelf");
this.Invoke("RemoveSelf", m_RemoveTime);
if (m_Num > 5) //处理⽂字动画
{
m_tweenNum++;
}
else {
m_Num++;
}
}
void DoTween() {
if (m_tweenNum <= 0)
{
flag = false;
return;
}
if (m_Tweener != null && m_Tweener.IsPlaying())
{
return;
}
m_Tweener = ansform.DOScale(3f, 0.25f).SetEase(Ease.InBack).OnComplete(() =>
{
= (++m_Num).ToString();
ansform.DOScale(1f, 0.25f).OnComplete(() => {
m_tweenNum--;
DoTween();
});
});
}
// Update is called once per frame
void Update()
{
if (m_tweenNum > 0 && !flag)
{
flag = true;
DoTween();
}
}
void OnDisable()
unity3d animation{
m_Tweener.Kill();
}
public void InitData(uint id,string senderName ,int num) {
m_ID = id;
m_SenderName = senderName;
m_Num = num;
}
public void RemoveSelf()
{
InGameFlowerPanel.Inst.ClearFlowerItem(m_ID);
this.CancelInvoke("RemoveSelf");
Destroy(gameObject);
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论