PopForms.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using SUIFW;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public enum PopType
  8. {
  9. PopOne = 1,
  10. PopTwo = 2
  11. }
  12. public class PopForms : BaseUIForms
  13. {
  14. public static PopForms Instance;
  15. public Text mainText;
  16. public Button popOneBtn;
  17. public Text popOneBtnText;
  18. public Button popTwoOkBtn;
  19. public Text popTwoOkBtnText;
  20. public Button popTwoCanelBtn;
  21. public Text popTwoCanelBtnText;
  22. private void Awake()
  23. {
  24. Instance = this;
  25. CurrentUIType.UIForms_Type = UIFormsType.PopUp;
  26. CurrentUIType.UIForms_ShowMode = UIFormsShowMode.ReverseChange;
  27. }
  28. public void ShowPublic(PopType popType, string msg, string btnmsg1 = "确定", Action ok = null, string btnmsg2 = "取消", Action cancel = null)
  29. {
  30. switch (popType)
  31. {
  32. case PopType.PopOne:
  33. ShowPopOne(btnmsg1, ok);
  34. break;
  35. case PopType.PopTwo:
  36. ShowPopTwo(btnmsg1, ok, btnmsg2, cancel);
  37. break;
  38. }
  39. mainText.text = msg;
  40. }
  41. public void ShowPopOne(string btnmsg1, Action ok)
  42. {
  43. popOneBtn.gameObject.SetActive(true);
  44. popOneBtn.onClick.RemoveAllListeners();
  45. popTwoOkBtn.gameObject.SetActive(false);
  46. popTwoCanelBtn.gameObject.SetActive(false);
  47. popOneBtnText.text = btnmsg1;
  48. popOneBtn.onClick.AddListener(() =>
  49. {
  50. CloseOrReturnUIForms();
  51. ok?.Invoke();
  52. }
  53. );
  54. }
  55. public void ShowPopTwo(string btnmsg1, Action ok, string btnmsg2, Action cancel)
  56. {
  57. popTwoOkBtn.gameObject.SetActive(true);
  58. popTwoCanelBtn.gameObject.SetActive(true);
  59. popTwoOkBtn.onClick.RemoveAllListeners();
  60. popTwoCanelBtn.onClick.RemoveAllListeners();
  61. popOneBtn.gameObject.SetActive(false);
  62. popTwoOkBtn.onClick.AddListener(() =>
  63. {
  64. CloseOrReturnUIForms();
  65. ok?.Invoke();
  66. });
  67. popTwoOkBtnText.text = btnmsg1;
  68. popTwoCanelBtn.onClick.AddListener(() =>
  69. {
  70. CloseOrReturnUIForms();
  71. cancel?.Invoke();
  72. });
  73. popTwoCanelBtnText.text = btnmsg2;
  74. }
  75. #region 窗体生命周期
  76. public override void Display()
  77. {
  78. base.Display();
  79. }
  80. public override void Redisplay()
  81. {
  82. base.Redisplay();
  83. }
  84. public override void Freeze()
  85. {
  86. base.Freeze();
  87. }
  88. public override void Hiding()
  89. {
  90. base.Hiding();
  91. }
  92. #endregion
  93. }