using GameLogic.Hero;
using UnityEngine;
using UnityEngine.UI;
namespace Fort23.Mono
{
[UIBinding(prefab = "Widget_Hero" )]
public partial class WidgetHero : UIComponent
{
private void Init()
{
}
public override void AddEvent()
{
}
public override void DelEvent()
{
}
public override void AddButtonEvent()
{
btnHero.onClick.AddListener(OnHeroClick);
}
private void OnHeroClick()
{
}
///
///
///
///
public void InitHero(HeroInfo heroInfo)
{
lv.text = heroInfo.lv.ToString();
// 最大星级展示个数(6星,只显示一颗星星,换颜色)
int maxShowStar = 5;
// 计算 当前星级 应该用什么星星的表现
int group = (heroInfo.star - 1) / maxShowStar;
int i = 1;
foreach (var star in stars)
{
GameObject starObj = star as GameObject;
SetStarImg(group, starObj);
if (heroInfo.star >= i)
{
starObj.SetActive(true);
}
else
{
starObj.SetActive(false);
}
i++;
}
}
private void SetStarImg(int group, GameObject starObj)
{
Image image = starObj.GetComponent();
// 执行对应的逻辑 (0)GradeIcon_Star_s_Yellow (1)GradeIcon_Star_s_Premium
switch (group)
{
case 0: // n = 1~5
image.name = "GradeIcon_Star_s_Yellow";
break;
case 1: // n = 6~10
image.name = "GradeIcon_Star_s_Premium";
break;
default: // 其他情况
image.name = "GradeIcon_Star_s_Yellow";
break;
}
}
}
}