GameoverHanler.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using ET.Client;
  2. using ET.EventType;
  3. using FairyGUI;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. namespace ET
  7. {
  8. [Event]
  9. public class RankEventHandler : BEvent<RankChangeEvent>
  10. {
  11. protected override async ETTask OnEvent(RankChangeEvent a)
  12. {
  13. GameoverEventHandler.RankList = a.InfoList;
  14. await ETTask.CompletedTask;
  15. }
  16. }
  17. [Event]
  18. public class GameoverEventHandler : BEvent<EventType.GameoverEvent>
  19. {
  20. public static List<RankInfo> RankList = new();
  21. public static bool IsGameOver = false;
  22. protected override async ETTask OnEvent(EventType.GameoverEvent args)
  23. {
  24. IsGameOver = true;
  25. GComponent view;
  26. if(args.winForce == 1)
  27. {
  28. view = await UIHelper.Create("CommonDialog", "GameoverSuccess");
  29. }
  30. else
  31. {
  32. view = await UIHelper.Create("CommonDialog", "GameoverFailed");
  33. }
  34. //等1秒,等排行榜数据
  35. await TimerComponent.Instance.WaitAsync(1000);
  36. view.GetChild("btn_ok").onClick.Set(async () =>
  37. {
  38. GRoot.inst.RemoveChild(view);
  39. view = await UIHelper.Create("paiming", "paiming");
  40. InitRankView(view);
  41. view.GetChild("btn_ok").onClick.Set(() =>
  42. {
  43. RankList = null;
  44. IsGameOver = false;
  45. UIHelper.RemoveAllUiExceptSth();
  46. GlobalViewMgr.Instance.ReOpenGame();
  47. EventSystem.Instance.Publish<ReOpenGame>();
  48. });
  49. });
  50. }
  51. //展示排行榜
  52. private void InitRankView(GComponent view)
  53. {
  54. var list = view.GetChild("list").asList;
  55. var data = RankList ?? new List<RankInfo>();
  56. int i = 0;
  57. GComponent chd;
  58. for (; i < data.Count; i++)
  59. {
  60. if (i >= list.numChildren)
  61. {
  62. chd = UIPackage.CreateObject("paiming", $"paiming_0{((i<3) ? (i+1) : 4)}").asCom;
  63. list.AddChild(chd);
  64. }
  65. else
  66. {
  67. chd = list.GetChildAt(i).asCom;
  68. chd.visible = true;
  69. }
  70. if(i >= 3)
  71. {
  72. chd.GetChild("rank").text = (i + 1).ToString();
  73. }
  74. chd.GetChild("name").text = data[i].Name;
  75. chd.GetChild("score").text = data[i].Value.ToString();
  76. var mask = chd.GetChild("icon").asCom;
  77. var icon = mask.GetChild("iconLoader").asLoader;
  78. var url = data[i].Url;
  79. if (!string.IsNullOrEmpty(url))
  80. {
  81. LoadHeadIcon(icon, url).Coroutine();
  82. }
  83. }
  84. for (; i < list.numChildren; i++)
  85. {
  86. list.GetChildAt(i).visible = false;
  87. }
  88. }
  89. private async ETTask LoadHeadIcon(GLoader loader, string url)
  90. {
  91. var tex = await UrlImageLoader.Instance.LoadImage(url);
  92. if (tex != null)
  93. {
  94. if (GRoot.inst.GetChild("paiming") != null)
  95. {
  96. loader.texture = new NTexture(tex);
  97. }
  98. }
  99. }
  100. }
  101. }