HeroBagPanel.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Collections.Generic;
  2. using Common.Utility.CombatEvent;
  3. using Core.Language;
  4. using Fort23.Core;
  5. using GameLogic.Hero;
  6. using UnityEngine;
  7. namespace Fort23.Mono
  8. {
  9. [UIBinding(prefab = "HeroBagPanel" )]
  10. public partial class HeroBagPanel : UIPanel
  11. {
  12. private void Init()
  13. {
  14. }
  15. protected override void AddEvent()
  16. {
  17. EventManager.Instance.AddEventListener(CustomEventType.MainLvUp, OnMainLvUp);
  18. }
  19. protected override void DelEvent()
  20. {
  21. EventManager.Instance.AddEventListener(CustomEventType.MainLvUp, OnMainLvUp);
  22. }
  23. public override void AddButtonEvent()
  24. {
  25. btnBack.onClick.AddListener(OnclickClose);
  26. }
  27. private void OnMainLvUp(IEventData e)
  28. {
  29. // SimpleEventData data = e as SimpleEventData;
  30. UpdateMainLv();
  31. }
  32. private void OnclickClose()
  33. {
  34. UIManager.Instance.HideUIUIPanel(this);
  35. }
  36. private void UpdateMainLv()
  37. {
  38. txtMainLv.text = LanguageManager.Instance.Text(64, PlayerManager.Instance.heroController.mainLevel);
  39. }
  40. public void InitPanel()
  41. {
  42. InitMainHeroWidget();
  43. UpdateMainLv();
  44. }
  45. private List<WidgetHero> widgetHeroes = new List<WidgetHero>();
  46. private async void InitMainHeroWidget()
  47. {
  48. widgetHeroes.Clear();
  49. int i = 0;
  50. foreach (KeyValuePair<int,HeroInfo> keyValuePair in PlayerManager.Instance.heroController.heroDicInLead)
  51. {
  52. RectTransform rectTransform = mainHeroes[i] as RectTransform;
  53. WidgetHero itemHero = await UIManager.Instance.CreateGComponent<WidgetHero>(null,
  54. poolName: "WidgetHero", root: rectTransform);
  55. itemHero.InitHeroForBag(keyValuePair.Value);
  56. widgetHeroes.Add(itemHero);
  57. i++;
  58. }
  59. }
  60. }
  61. }