SceneChangeFinishEvent_CreateHUD.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using CommonAI.Zone;
  2. using ET.EventType;
  3. using FairyGUI;
  4. namespace ET.Client
  5. {
  6. [Event(SceneType.Client)]
  7. public class SceneChangeFinishEvent_CreateUIHelp : BEvent<SceneLoadFinish>
  8. {
  9. public override void OnEvent(SceneLoadFinish a)
  10. {
  11. asyncTask().Coroutine();
  12. }
  13. private async ETTask asyncTask()
  14. {
  15. Log.Debug("loading HUD");
  16. var view = await UIHelper.Create("HUD");
  17. HUDMgr.InitView(view);
  18. }
  19. }
  20. [Event(SceneType.None)]
  21. public class SkillChangeEventHandler : BEvent<SkillChangeEvent>
  22. {
  23. public override void OnEvent(SkillChangeEvent a)
  24. {
  25. var view = UIHelper.GetUI("HUD") as GComponent;
  26. if(view != null)
  27. {
  28. HUDMgr.InitView(view);
  29. }
  30. }
  31. }
  32. public static class HUDMgr
  33. {
  34. public static void InitView(GComponent view)
  35. {
  36. var btn1 = view.GetChild("btn_skill1");
  37. var btn2 = view.GetChild("btn_skill2");
  38. var actor = UnitMgr.Instance.Actor;
  39. if (actor == null || !actor.IsSkillOk)
  40. {
  41. btn1.visible = false;
  42. btn2.visible = false;
  43. return;
  44. }
  45. btn1.visible = actor.GetSkill(0) != null;
  46. btn2.visible = actor.GetSkill(1) != null;
  47. var img = view.GetChild("img_direction");
  48. btn1.onClick.Set(() => {
  49. EventSystem.Instance.Publish<LaunchSkillEvent>(LaunchSkillEvent.Static.Clone(0)) ;
  50. });
  51. btn2.onClick.Set(() => {
  52. EventSystem.Instance.Publish<LaunchSkillEvent>(LaunchSkillEvent.Static.Clone(1));
  53. });
  54. }
  55. }
  56. }