RegionItem.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System.Collections.Generic;
  2. using Excel2Json;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace Mono
  6. {
  7. [UIBinding(prefab = "RegionItem")]
  8. public class RegionItem : UICom
  9. {
  10. public Button Btn_Region;
  11. public Text Text_RegionName;
  12. public RectTransform PoetryItemRoot;
  13. public List<PoetryItem> CurPoetryItems = new List<PoetryItem>();
  14. public override void GetUIData()
  15. {
  16. Btn_Region = UIData.Get<Button>("Btn_Region");
  17. Text_RegionName = UIData.Get<Text>("Text_RegionName");
  18. PoetryItemRoot = UIData.Get<RectTransform>("PoetryItemRoot");
  19. }
  20. public override void AddButtonEvent()
  21. {
  22. Btn_Region.onClick.AddListener(() => { CreatPoetryItem(); });
  23. }
  24. public void CreatPoetryItem()
  25. {
  26. if (CurPoetryItems.Count > 0)
  27. {
  28. for (var i = 0; i < CurPoetryItems.Count; i++)
  29. {
  30. UIManager.Instance.RecUICom(this, CurPoetryItems[i]);
  31. }
  32. CurPoetryItems.Clear();
  33. return;
  34. }
  35. for (var i = 0; i < RegionConfig.Poets.Length; i++)
  36. {
  37. PoetConfig poetConfig = ConfigComponent.Instance.Get<PoetConfig>(RegionConfig.Poets[i]);
  38. PoetryItem poetryItem = UIManager.Instance.CreatUICom<PoetryItem>(this, PoetryItemRoot);
  39. poetryItem.CustomInit(poetConfig);
  40. CurPoetryItems.Add(poetryItem);
  41. }
  42. // PoetryItem poetryItem = UIManager.Instance.CreatUICom<PoetryItem>(this, PoetryItemRoot);
  43. // poetryItem.CustomInit("白帝");
  44. // CurPoetryItems.Add(poetryItem);
  45. // PoetryItem poetryItem1 = UIManager.Instance.CreatUICom<PoetryItem>(this, PoetryItemRoot);
  46. // poetryItem1.CustomInit("黑帝");
  47. // CurPoetryItems.Add(poetryItem1);
  48. // PoetryItem poetryItem2 = UIManager.Instance.CreatUICom<PoetryItem>(this, PoetryItemRoot);
  49. // poetryItem2.CustomInit("金帝");
  50. // CurPoetryItems.Add(poetryItem2);
  51. }
  52. public override void Show()
  53. {
  54. base.Show();
  55. }
  56. public RegionConfig RegionConfig;
  57. public void CustomInit(RegionConfig regionConfig)
  58. {
  59. RegionConfig = regionConfig;
  60. Text_RegionName.text = regionConfig.name;
  61. }
  62. }
  63. }