Files
MinFt/Client/Assets/Scripts/UI/RewardItem.cs
Liubing\LB 3d8d4d18f3 first commit
先修复一下,错误的场景

删除不必要的钓场资产

修复into场景

update:更新meta文件,修复报错

update:修复资源

修复第一章节建造

修复建造第三章

update:删除多余内容

update:更新README.md

update:还原图标

update:更新README

update:更新配置
2026-04-28 02:17:22 +08:00

109 lines
2.4 KiB
C#

using asap.core;
using cfg;
using GameCore;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class RewardItem : MonoBehaviour
{
private Tables _tables => GContext.container.Resolve<Tables>();
public Image icon;
public TMP_Text text_num;
public GameObject received;
public Button btn_click;
private int id = 0;
private float count = 0;
bool isClick = false;
#if UNITY_EDITOR
private void Reset()
{
Awake();
}
#endif
private void Awake()
{
if (icon == null)
{
icon = transform.Find("icon").GetComponent<Image>();
}
if (text_num == null)
{
text_num = transform.Find("text_num")?.GetComponent<TMP_Text>();
}
if (received == null)
{
received = transform.Find("received")?.gameObject;
}
if (btn_click == null)
{
btn_click = GetComponent<Button>();
}
}
public void SetReceived(bool _isReceived)
{
if (received != null)
{
received.SetActive(_isReceived);
}
}
private void Start()
{
if (btn_click != null)
{
btn_click.onClick.AddListener(OnClick);
}
}
void OnClick()
{
if (id == 0 || isClick == false)
{
return;
}
GContext.container.Resolve<PlayerItemData>().ShowItemTips(id, transform);
}
public void SetData(ItemData itemData, bool isClick = false)
{
this.isClick = isClick;
gameObject.SetActive(true);
SetReceived(false);
id = itemData.id;
count = itemData.count;
GContext.container.Resolve<IUIService>().SetImageSprite(icon, _tables.GetItemIconName(id), BasePanel.PanelName);
if (text_num)
{
int c = (int)count;
if (c > 1)
{
text_num.text = ConvertTools.GetNumberString((int)count);
}
else
{
text_num.text = "";
}
}
}
public void SetData(int itemId, string text = null)
{
id = itemId;
GContext.container.Resolve<IUIService>().SetImageSprite(icon, _tables.GetItemIconName(id), BasePanel.PanelName);
if (text == "-1")
{
text = null;
}
if (text_num)
{
text_num.text = text;
}
gameObject.SetActive(true);
}
}