177 lines
4.1 KiB
C#
177 lines
4.1 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2020-09-12
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "CostWidget" company="KUNPO"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using TMPro;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
namespace G.UI
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 费用组件
|
|||
|
/// </summary>
|
|||
|
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
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="text"></param>
|
|||
|
public void SetText(string text)
|
|||
|
{
|
|||
|
_tmpCount.text = text;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="iconInfo"></param>
|
|||
|
public void SetIcon(string[] iconInfo)
|
|||
|
{
|
|||
|
IconProxy.Instance.SetSprite(_imgIcon, iconInfo);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="itemId"></param>
|
|||
|
/// <param name="count"></param>
|
|||
|
public void SetPrice(int itemId, int count, bool enough = true)
|
|||
|
{
|
|||
|
var prop = ItemProxy.Instance.GetStaticItem<ItemProp>(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<ItemProp>(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}";
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="itemInfo"></param>
|
|||
|
/// <param name="enough"></param>
|
|||
|
public void SetPrice(Item.ItemInfo itemInfo, bool enough = true)
|
|||
|
{
|
|||
|
SetPrice(itemInfo.id, itemInfo.count, enough);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 自己检测
|
|||
|
/// </summary>
|
|||
|
/// <param name="itemId"></param>
|
|||
|
/// <param name="count"></param>
|
|||
|
public void SetAndCheckPrice(int itemId, int count)
|
|||
|
{
|
|||
|
var prop = ItemProxy.Instance.GetStaticItem<ItemProp>(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);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <param name="count"></param>
|
|||
|
public void SetPriceWithMax(int id, int count)
|
|||
|
{
|
|||
|
var prop = ItemProxy.Instance.GetStaticItem<ItemProp>(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;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="itemInfo"></param>
|
|||
|
public void SetPriceWithMax(Item.ItemInfo itemInfo)
|
|||
|
{
|
|||
|
SetPriceWithMax(itemInfo.id, itemInfo.count);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Unity
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
SetViewData();
|
|||
|
_oriColor = _tmpCount.color;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|