UIAlertComponentSystem.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using static System.Net.Mime.MediaTypeNames;
  7. namespace ET.Client
  8. {
  9. [FriendOf(typeof(UIAlertComponent))]
  10. public static class UIAlertComponentSystem
  11. {
  12. [ObjectSystem]
  13. public class UIAlertComponentAwakeSystem : AwakeSystem<UIAlertComponent>
  14. {
  15. protected override void Awake(UIAlertComponent self, params object[] param)
  16. {
  17. ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
  18. self.cancelTxt = rc.Get<GameObject>("cancelTxt");
  19. self.sureTxt = rc.Get<GameObject>("sureTxt");
  20. self.contentTxt = rc.Get<GameObject>("contentTxt");
  21. self.titleTxt = rc.Get<GameObject>("titleTxt");
  22. self.cancelBtn = rc.Get<GameObject>("cancelBtn");
  23. self.cancelBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCloseBtn(0); });
  24. self.sureBtn = rc.Get<GameObject>("sureBtn");
  25. self.sureBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCloseBtn(1); });
  26. Dictionary<string,object> dic = param[0] as Dictionary<string,object>;
  27. string title = dic["title"] as string;
  28. string content = dic["content"] as string;
  29. string yesTxt = dic["yesTxt"] as string;
  30. string cancelTxt = dic["cancelTxt"] as string;
  31. self.callback = dic["callback"] as Action<object>;
  32. self.Init(title, content, yesTxt, cancelTxt);
  33. }
  34. }
  35. private static void Init(this UIAlertComponent self, string title, string content, string yesTxt, string cancelTxt)
  36. {
  37. self.titleTxt.GetComponent<UnityEngine.UI.Text>().text = title;
  38. self.cancelTxt.GetComponent<UnityEngine.UI.Text>().text = cancelTxt;
  39. self.sureTxt.GetComponent<UnityEngine.UI.Text>().text = yesTxt;
  40. self.contentTxt.GetComponent<UnityEngine.UI.Text>().text = content;
  41. }
  42. public static async void OnCloseBtn(this UIAlertComponent self,int index)
  43. {
  44. await SoundManager.Instance.PlaySound("clickbtnsound");
  45. self.callback?.Invoke(index);
  46. self.callback = null;
  47. self.OnCloseAsync();
  48. }
  49. public static async void OnCloseAsync(this UIAlertComponent self)
  50. {
  51. await UIHelper.Remove(self.ClientScene(),UIType.UIAlert);
  52. }
  53. }
  54. }