unity_art_puzzle_playable_luna/APPlayableLuna/Assets/Scripts/FlyAnimComp.cs

94 lines
3.0 KiB
C#

using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
namespace GuruClient
{
public enum FlyAnimType
{
Coin,
Star
}
public class FlyAnimComp : MonoBehaviour
{
public Transform endPos;
public Text txtChange;
public Text txtCurrent;
public GameObject animObj;
public Transform animNode;
public void Play(int changeVal, int animNum, FlyAnimType type)
{
gameObject.SetActive(true);
txtChange.gameObject.SetActive(true);
txtChange.text = "+" + changeVal;
txtChange.transform.DOLocalMoveY(200f, 1.5f).SetDelay(0.2f);
txtChange.DOFade(0f, 1.5f).SetDelay(0.2f);
int oldVal = 0;
int endVal = 0;
if (type == FlyAnimType.Coin)
{
oldVal = 0;
endVal = 20;
}
txtCurrent.text = CoinHelper.ConvertValue(oldVal);
// 使用DOTween实现数字滚动
DOTween.To(value => { txtCurrent.text = CoinHelper.ConvertValue((int) value).ToString(); },
startValue: oldVal,
endValue: endVal, duration: 0.05f * (animNum - 1)).SetDelay(1f)
.SetAutoKill();
animNode.gameObject.SetActive(true);
int childCount = animNode.childCount;
for (int i = 0; i < childCount; i++)
{
animNode.GetChild(i).gameObject.SetActive(false);
}
GameObject prefab = animNode.GetChild(0).gameObject;
float delayTime = 0;
for (int i = 0; i < animNum; i++)
{
Sequence sq = DOTween.Sequence();
sq.SetDelay(delayTime);
GameObject obj;
if (i >= childCount)
{
obj = Instantiate(prefab, animNode);
}
else
{
obj = animNode.GetChild(i).gameObject;
}
obj.SetActive(false);
obj.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f);
obj.transform.localPosition = new Vector3(UnityEngine.Random.Range(-100f, 100f),
UnityEngine.Random.Range(-100f, 100f), 0);
sq.AppendCallback(delegate { obj.SetActive(true); });
sq.Append(obj.transform.DOScale(1f, 0.3f));
sq.Join(obj.GetComponent<Image>().DOFade(1, 0.3f));
sq.Join(obj.transform.DOLocalMoveY(obj.transform.position.y - UnityEngine.Random.Range(0, 150),
0.3f));
sq.SetDelay(0.1f);
sq.Append(obj.transform.DOMove(endPos.transform.position, 0.6f).OnComplete(delegate {
Debug.Log("金币播放震动");
}));
sq.SetAutoKill();
sq.OnComplete(delegate { obj.SetActive(false); });
delayTime += 0.05f;
}
}
}
}