using System.Collections; using System.Collections.Generic; using Cysharp.Threading.Tasks; using DG.Tweening; using GameConfig.giftConfig; using TEngine; using TMPro; using UnityEngine; using UnityEngine.UI; namespace GameLogic { public class UIGiftItem : MonoBehaviour { // Start is called before the first frame update public TextMeshProUGUI m_GiftName; public TextMeshProUGUI m_InfoTex; public TextMeshProUGUI m_NumTex; public RawImage m_HeadIcon; public Image m_GiftIcon; //public Image m_Group; public async void OnInit(UnitPlayerData unitPlayerData, GiftConfig giftConfig, int num) { //// 随机播放 //GameModule.Audio.Play(TEngine.AudioType.UISound, "礼物UI弹窗" + Random.Range(1, 5)); //m_Group.sprite = GameModule.Resource.LoadAsset("Z_lw_t_box_" + (giftConfig.Id - 1)); m_GiftName.text = unitPlayerData.protCustMessageData.nickName; AsyncImageDownload.Instance.SetAsyncImage(unitPlayerData.protCustMessageData.imgURL, m_HeadIcon); StartCoroutine(ScrollNumber(num)); // Start the number scrolling coroutine m_InfoTex.text = "送" + giftConfig.Name; m_GiftIcon.material = GameModule.Resource.LoadAsset("gift" + giftConfig.Id + "_Left"); await UniTask.Delay(2000); if (this != null && this.gameObject != null && transform.parent != null) { Destroy(gameObject); } } private IEnumerator ScrollNumber(int targetNumber) { int currentNumber = 0; float duration = 1.0f; // Duration of the scrolling effect float elapsed = 0f; while (elapsed < duration) { elapsed += Time.deltaTime; currentNumber = (int)Mathf.Lerp(0, targetNumber, elapsed / duration); m_NumTex.text = "x" + currentNumber; yield return null; } m_NumTex.text = "x" + targetNumber; // Ensure the final number is set } } }