标签:
在游戏中,经常有这样的需要数字从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_NameText.text = m_SenderName; if (m_Num <= 5) { m_NumText.text = 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 = m_NumText.transform.DOScale(3f, 0.25f).SetEase(Ease.InBack).OnComplete(() => { m_NumText.text = (++m_Num).ToString(); m_NumText.transform.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() { 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); } }
标签:
原文地址:http://www.cnblogs.com/heartgame/p/5687829.html