Files
Main/Assets/GameAssets/Resources/GameUI/Common/UIItemComponent/UIItemComponent.cs
2025-01-25 04:38:09 +08:00

92 lines
2.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Thousandto.Code.Center;
using Thousandto.Code.Global;
/// <summary>
/// 物品component组件用于显示消耗物品显示
/// </summary>
using Thousandto.Core.Base;
using Thousandto.GameUI.Form;
using UnityEngine;
namespace Thousandto.Plugins.Common
{
//描述的属性信息
public class DescItemInfo
{
public int ItemID { get; set; }
public long Num { get; set; }
public bool IsBind { get; set; }
}
//属性组件
public class UIItemComponent : IUIComponent<UIItemComponent, DescItemInfo>
{
private Transform _trans;
private UIItem _item;
private DescItemInfo _data;
public UIItemComponent(Transform trans)
{
_trans = trans;
_item = _trans.RequireComponent<UIItem>();
SetActive(false);
}
public UIItemComponent Clone()
{
var newGo = GameObject.Instantiate(_trans.gameObject) as GameObject;
var ep = new UIItemComponent(newGo.transform);
ep._trans.parent = _trans.parent;
UnityUtils.Reset(ep._trans);
return ep;
}
public void SetActive(bool active)
{
_trans.gameObject.SetActive(active);
}
public void SetData(DescItemInfo data)
{
_data = data;
RefreshData();
}
public void SetName(string name)
{
_trans.name = name;
}
public void RefreshData()
{
if (_data != null)
{
_trans.gameObject.SetActive(true);
_item.InitializationWithIdAndNum(_data.ItemID, _data.Num, _data.IsBind);
}
}
public Transform GetTrans()
{
return _trans;
}
/// <summary>
/// 根据背包数量设置数量显示
/// </summary>
public void OnSetNumByBack()
{
if(_data != null)
{
long haveCont = GameCenter.ItemContianerSystem.GetItemCountFromCfgId(_data.ItemID);
_item.OnSetNum(string.Format("{0}/{1}", haveCont, _data.Num));
if(haveCont < _data.Num)
{
_item.OnSetNumColor(Color.red);
}
else
{
_item.OnSetNumColor(Color.green);
}
}
}
}
}