78 lines
2.7 KiB
C#
Raw Normal View History

2025-04-18 19:18:15 +08:00
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
2025-05-08 23:23:31 +08:00
public TextMeshProUGUI m_GiftName;
2025-04-18 19:18:15 +08:00
public TextMeshProUGUI m_InfoTex;
public TextMeshProUGUI m_NumTex;
2025-06-26 18:31:32 +08:00
public Text m_tmpTeamName;
2025-04-18 19:18:15 +08:00
public RawImage m_HeadIcon;
public Image m_GiftIcon;
2025-05-08 23:23:31 +08:00
//public Image m_Group;
2025-04-18 19:18:15 +08:00
2025-06-04 19:22:53 +08:00
private void Awake()
{
2025-06-27 11:15:15 +08:00
//this.gameObject.GetComponent<Canvas>().sortingLayerName = "UI02";
2025-06-04 19:22:53 +08:00
}
2025-04-18 19:18:15 +08:00
public async void OnInit(UnitPlayerData unitPlayerData, GiftConfig giftConfig, int num)
{
2025-05-09 00:35:25 +08:00
//// 随机播放
//GameModule.Audio.Play(TEngine.AudioType.UISound, "礼物UI弹窗" + Random.Range(1, 5));
2025-04-18 19:18:15 +08:00
2025-05-08 23:23:31 +08:00
//m_Group.sprite = GameModule.Resource.LoadAsset<Sprite>("Z_lw_t_box_" + (giftConfig.Id - 1));
2025-06-27 11:55:11 +08:00
if (unitPlayerData == null)
{
Destroy(gameObject);
return;
}
Log.Debug("送礼玩家阵营id:" + unitPlayerData.teamId);
2025-05-26 23:16:08 +08:00
m_tmpTeamName.text = DataGameSceneManager.Instance.GetStrs(int.Parse(unitPlayerData.teamId) - 1);
2025-05-08 23:23:31 +08:00
m_GiftName.text = unitPlayerData.protCustMessageData.nickName;
2025-04-18 19:18:15 +08:00
AsyncImageDownload.Instance.SetAsyncImage(unitPlayerData.protCustMessageData.imgURL, m_HeadIcon);
StartCoroutine(ScrollNumber(num)); // Start the number scrolling coroutine
m_InfoTex.text = "送" + giftConfig.Name;
2025-05-28 15:26:42 +08:00
m_GiftIcon.sprite = GameModule.Resource.LoadAsset<Sprite>("1_" + (giftConfig.Id - 1));
//m_GiftIcon.material = GameModule.Resource.LoadAsset<Material>("gift" + giftConfig.Id + "_Left");
2025-04-18 19:18:15 +08:00
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
}
}
}