123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System.Threading.Tasks;
- using Fort23.UTool;
- 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()
- {
- LogTool.Log("添加英雄点击事件");
- btnHero.onClick.AddListener(OnHeroClick);
- }
- private async void OnHeroClick()
- {
- LogTool.Log("点击英雄");
- await OpenHeroDetailPanel();
- }
- private async Task OpenHeroDetailPanel()
- {
- // HeroDetailPanel heroDetailPanel = UIManager.Instance.GetComponent<HeroDetailPanel>();
- // if (heroDetailPanel == null)
- // {
- // heroDetailPanel = await UIManager.Instance.LoadAndOpenPanel<HeroDetailPanel>(Callback);
- // }
- HeroDetailPanel heroDetailPanel = await UIManager.Instance.LoadAndOpenPanel<HeroDetailPanel>(Callback);
- heroDetailPanel.InitHeroDetailPanel(heroInfo);
- }
- private void Callback(HeroDetailPanel obj)
- {
- LogTool.Log("HeroDetailPanel 加载完成");
- }
- private HeroInfo heroInfo;
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="heroInfo"></param>
- public void InitHero(HeroInfo heroInfo)
- {
- // GetComponent<RectTransform>().anchorMin = new Vector2(0.5f, 0.5f);
- // GetComponent<RectTransform>().anchorMax = new Vector2(0.5f, 0.5f);
- this.heroInfo = heroInfo;
- lv.text = heroInfo.lv.ToString();
-
- // 最大星级展示个数(6星,只显示一颗星星,换颜色)
- int maxShowStar = 5;
- // 计算 当前星级 应该用什么星星的表现
- int group = (heroInfo.star - 1) / maxShowStar;
- int i = 1;
- foreach (GameObject star in stars)
- {
- // Image image = star.GetComponent<Image>();
- SetStarImg(group, star);
-
- if (heroInfo.star >= i)
- {
- star.SetActive(true);
- }
- else
- {
- star.SetActive(false);
- }
- i++;
- }
- }
- private void SetStarImg(int group, GameObject starObj)
- {
- Image image = starObj.GetComponent<Image>();
- // 执行对应的逻辑 (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;
- }
- }
- }
- }
|