WarningUI.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using UnityEngine.Events;
  3. using UnityEngine.UI;
  4. public class WarningUI : BaseUI
  5. {
  6. public delegate void OnYesClick();
  7. public delegate void OnNoClick();
  8. private Button yesButton;
  9. private Button noButton;
  10. private Text label;
  11. private OnYesClick nowClick;
  12. private OnNoClick NoClick;
  13. protected override void OnShow(WarningUI.OnYesClick onYesClick, object param)
  14. {
  15. base.OnShow(onYesClick, param);
  16. nowClick = onYesClick;
  17. label.text = param.ToString();
  18. }
  19. protected override void OnShow(OnYesClick onYesClick, OnNoClick onNoClick, object param)
  20. {
  21. base.OnShow(onYesClick, onNoClick, param);
  22. nowClick = onYesClick;
  23. NoClick = onNoClick;
  24. label.text = param.ToString();
  25. }
  26. protected override void OnHide()
  27. {
  28. base.OnHide();
  29. }
  30. protected override void OnAwake()
  31. {
  32. base.OnAwake();
  33. }
  34. protected override void OnInit()
  35. {
  36. base.OnInit();
  37. base.CacheTransform.SetAsLastSibling();
  38. this.yesButton = base.transform.Find("Content/Yes").GetComponent<Button>();
  39. this.noButton = base.transform.Find("Content/No").GetComponent<Button>();
  40. this.label = base.transform.Find("Content/Label").GetComponent<Text>();
  41. this.yesButton.onClick.AddListener(new UnityAction(this.OnClickYes));
  42. this.noButton.onClick.AddListener(new UnityAction(this.OnClickNo));
  43. }
  44. private void OnClickYes()
  45. {
  46. if (nowClick != null)
  47. {
  48. nowClick();
  49. }
  50. Hide();
  51. }
  52. private void OnClickNo()
  53. {
  54. if (NoClick != null)
  55. {
  56. NoClick();
  57. }
  58. Hide();
  59. }
  60. }