56 lines
1.5 KiB
C#
56 lines
1.5 KiB
C#
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class BJEndUI : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI tMP_beishu;
|
|
public TextMeshProUGUI tMP_score;
|
|
public TMP_SpriteAsset goldSprite;
|
|
public TMP_SpriteAsset SilverSprite;
|
|
|
|
public bool useScoreAnim = false; // 是否启用分数递增动画
|
|
|
|
private void Awake()
|
|
{
|
|
Destroy(gameObject, 5);
|
|
}
|
|
|
|
public void Init(int beishu, int score, bool isMine = false)
|
|
{
|
|
// 自己爆奖用金色精灵,别人用银色
|
|
tMP_beishu.spriteAsset = isMine ? goldSprite : SilverSprite;
|
|
tMP_score.spriteAsset = isMine ? goldSprite : SilverSprite;
|
|
|
|
tMP_beishu.text = "<sprite=6>"+ beishu.ToString();
|
|
|
|
if (useScoreAnim)
|
|
StartCoroutine(ScoreAnim(score));
|
|
else
|
|
tMP_score.text = score.ToString();
|
|
}
|
|
|
|
private IEnumerator ScoreAnim(int target)
|
|
{
|
|
float duration = 1f;
|
|
float elapsed = 0f;
|
|
tMP_score.text = "0";
|
|
|
|
// 放大
|
|
Vector3 normalScale = tMP_score.transform.localScale;
|
|
tMP_score.transform.DOScale(normalScale * 1.3f, duration * 0.3f).SetEase(Ease.OutBack);
|
|
|
|
while (elapsed < duration)
|
|
{
|
|
elapsed += Time.deltaTime;
|
|
tMP_score.text = ((int)(target * elapsed / duration)).ToString();
|
|
yield return null;
|
|
}
|
|
|
|
tMP_score.text = target.ToString();
|
|
tMP_score.transform.DOScale(normalScale, 0.15f).SetEase(Ease.InBack);
|
|
}
|
|
}
|