// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2020-09-12 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using TMPro; using UnityEngine; using UnityEngine.UI; namespace G.UI { /// /// 费用组件 /// public class CostWidget : KUIWidget { #region Field #pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null [KUIFlag] KUIImage _imgQuality; [KUIFlag] Image _imgIcon; [KUIFlag] TextMeshProUGUI _tmpCount; #pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null private Color _oriColor; #endregion #region Method /// /// /// /// public void SetText(string text) { _tmpCount.text = text; } /// /// /// /// public void SetIcon(string[] iconInfo) { IconProxy.Instance.SetSprite(_imgIcon, iconInfo); } /// /// /// /// /// public void SetPrice(int itemId, int count, bool enough = true) { var prop = ItemProxy.Instance.GetStaticItem(itemId); if (prop != null) { IconProxy.Instance.SetSprite(_imgIcon, prop.icon); if (_imgQuality) _imgQuality.ShowSprite(prop.quality); } _tmpCount.color = enough ? _oriColor : Color.red; _tmpCount.text = "x" + count.ToString(); } public void SetPrice(int itemId, int cur, int max) { var prop = ItemProxy.Instance.GetStaticItem(itemId); if (prop != null) { if (itemId == 3002) { _imgIcon.gameObject.SetActive(false); } else { _imgIcon.gameObject.SetActive(true); } IconProxy.Instance.SetSprite(_imgIcon, prop.icon); if (_imgQuality) _imgQuality.ShowSprite(prop.quality); } _tmpCount.color = cur >= max ? _oriColor : Color.red; _tmpCount.text = $"{cur}/{max}"; } /// /// /// /// /// public void SetPrice(Item.ItemInfo itemInfo, bool enough = true) { SetPrice(itemInfo.id, itemInfo.count, enough); } /// /// 自己检测 /// /// /// public void SetAndCheckPrice(int itemId, int count) { var prop = ItemProxy.Instance.GetStaticItem(itemId); if (prop != null) { IconProxy.Instance.SetSprite(_imgIcon, prop.icon); if (_imgQuality) _imgQuality.ShowSprite(prop.quality); } _tmpCount.text = count.ToString(); _tmpCount.color = MoneyProxy.Instance.CheckMoney(itemId, count) ? _oriColor : Color.red; } public void SetAndCheckPrice(Item.ItemInfo itemInfo) { SetAndCheckPrice(itemInfo.id, itemInfo.count); } /// /// /// /// /// public void SetPriceWithMax(int id, int count) { var prop = ItemProxy.Instance.GetStaticItem(id); if (prop != null) { IconProxy.Instance.SetSprite(_imgIcon, prop.icon); if (_imgQuality) _imgQuality.ShowSprite(prop.quality); } int cur = MoneyProxy.Instance.GetMoney(id); _tmpCount.text = $"{cur}/{count}"; _tmpCount.color = cur >= count ? _oriColor : Color.red; } /// /// /// /// public void SetPriceWithMax(Item.ItemInfo itemInfo) { SetPriceWithMax(itemInfo.id, itemInfo.count); } #endregion #region Unity /// /// /// private void Awake() { SetViewData(); _oriColor = _tmpCount.color; } #endregion } }