53 lines
1.3 KiB
C#
53 lines
1.3 KiB
C#
using GeometryTD.Definition;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace GeometryTD.UI
|
|
{
|
|
public class IconArea : MonoBehaviour
|
|
{
|
|
[SerializeField] private Image _board;
|
|
|
|
[SerializeField] private Image _icon;
|
|
|
|
private IconAreaContext _context;
|
|
|
|
public void OnInit(IconAreaContext context)
|
|
{
|
|
if (context == null)
|
|
{
|
|
Log.Error("Icon area need IconAreaContext.");
|
|
return;
|
|
}
|
|
|
|
_context = context;
|
|
SetIcon(_context.Icon);
|
|
SetRarity(_context.Rarity);
|
|
}
|
|
|
|
public void SetIcon(Sprite sprite)
|
|
{
|
|
_icon.sprite = sprite;
|
|
}
|
|
|
|
public void SetRarity(RarityType rarity)
|
|
{
|
|
_board.color = rarity switch
|
|
{
|
|
RarityType.White => Color.white,
|
|
RarityType.Green => Color.green,
|
|
RarityType.Blue => Color.blue,
|
|
RarityType.Purple => Color.magenta,
|
|
RarityType.Red => Color.red,
|
|
_ => Color.clear,
|
|
};
|
|
}
|
|
|
|
public void OnReset()
|
|
{
|
|
SetIcon(null);
|
|
SetRarity(RarityType.None);
|
|
}
|
|
}
|
|
} |