GameoverHanler.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. EventSystem.Instance.Publish<ReOpenGame>();
  47. });
  48. });
  49. }
  50. //展示排行榜
  51. private void InitRankView(GComponent view)
  52. {
  53. var list = view.GetChild("list").asList;
  54. var data = RankList;
  55. int i = 0;
  56. GComponent chd;
  57. for (; i < data.Count; i++)
  58. {
  59. if (i >= list.numChildren)
  60. {
  61. chd = UIPackage.CreateObject("paiming", $"paiming_0{((i<3) ? (i+1) : 4)}").asCom;
  62. list.AddChild(chd);
  63. }
  64. else
  65. {
  66. chd = list.GetChildAt(i).asCom;
  67. chd.visible = true;
  68. }
  69. if(i >= 3)
  70. {
  71. chd.GetChild("rank").text = (i + 1).ToString();
  72. }
  73. chd.GetChild("name").text = data[i].Name;
  74. chd.GetChild("score").text = data[i].Value.ToString();
  75. }
  76. for (; i < list.numChildren; i++)
  77. {
  78. list.GetChildAt(i).visible = false;
  79. }
  80. }
  81. }
  82. }