BasePop.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using LitJson;
  2. using SC.XR.Unity;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. using XRTool.Util;
  9. using XRTool.WorldUI;
  10. namespace ShadowStudio.UI
  11. {
  12. public enum PopType
  13. {
  14. Cancel = 0,
  15. Normal = 1
  16. }
  17. [RequireComponent(typeof(WorldDlg))]
  18. public class BasePop : MonoBehaviour
  19. {
  20. public string title = "";
  21. public string msg = "";
  22. public PopType popType = PopType.Normal;
  23. private Button cancelBtn;
  24. private Button defineBtn;
  25. private Button okBtn;
  26. private SCInputField scInputField;
  27. public bool ifneedInput = false;
  28. public string btnText1;
  29. public string btnText2;
  30. public Action callBack1;
  31. public Action callBack2;
  32. public Action<string> callBack3;
  33. WorldDlg dlg;
  34. private Action closeBack;
  35. public void OnClose(Action callback)
  36. {
  37. closeBack = callback;
  38. }
  39. // Start is called before the first frame update
  40. void Start()
  41. {
  42. btnText1 = LanguageMgr.Instance.GetMessage("1066").Message;
  43. btnText2 = LanguageMgr.Instance.GetMessage("1058").Message;
  44. }
  45. public void init()
  46. {
  47. dlg = GetComponent<WorldDlg>();
  48. dlg.showDlg();
  49. cancelBtn = dlg.GetBreadthChild<Button>("CancelBtn");
  50. Text tx = dlg.GetBreadthChild<Text>("TitleText");
  51. tx.text = title;
  52. Text tx2 = dlg.GetBreadthChild<Text>("MessageText");
  53. tx2.text = msg;
  54. cancelBtn = dlg.GetBreadthChild<Button>("CancelBtn");
  55. TextMesh cancelText = UnityUtil.GetBreadthChild<TextMesh>(cancelBtn.transform, "TextMesh");
  56. cancelText.text = btnText2;
  57. defineBtn = dlg.GetBreadthChild<Button>("DefineBtn");
  58. TextMesh defineText = UnityUtil.GetBreadthChild<TextMesh>(defineBtn.transform, "TextMesh");
  59. defineText.text = btnText1;
  60. okBtn = dlg.GetBreadthChild<Button>("OkBtn");
  61. TextMesh okText = UnityUtil.GetBreadthChild<TextMesh>(okBtn.transform, "TextMesh");
  62. okText.text = btnText1;
  63. scInputField = dlg.GetBreadthChild<SCInputField>("SCInputField");
  64. switch (popType)
  65. {
  66. case PopType.Cancel:
  67. okBtn.gameObject.SetActive(false);
  68. cancelBtn.gameObject.SetActive(true);
  69. defineBtn.gameObject.SetActive(true);
  70. break;
  71. case PopType.Normal:
  72. okBtn.gameObject.SetActive(true);
  73. cancelBtn.gameObject.SetActive(false);
  74. defineBtn.gameObject.SetActive(false);
  75. break;
  76. }
  77. cancelBtn.onClick.AddListener(cancelClick);
  78. defineBtn.onClick.AddListener(defineClick);
  79. okBtn.onClick.AddListener(okClick);
  80. if (ifneedInput)
  81. {
  82. tx2.gameObject.SetActive(false);
  83. scInputField.gameObject.SetActive(true);
  84. }
  85. }
  86. void defineClick()
  87. {
  88. dlg.hideDlg(() => {
  89. if (ifneedInput)
  90. {
  91. callBack3?.Invoke(scInputField.text);
  92. }
  93. else
  94. {
  95. callBack1?.Invoke();
  96. }
  97. Destroy(this.gameObject);
  98. });
  99. }
  100. void cancelClick()
  101. {
  102. dlg.hideDlg(() => {
  103. if (callBack2 != null)
  104. {
  105. callBack2.Invoke();
  106. }
  107. Destroy(this.gameObject);
  108. });
  109. }
  110. void okClick()
  111. {
  112. dlg.hideDlg(() => {
  113. if (callBack1 != null)
  114. {
  115. callBack1.Invoke();
  116. }
  117. Destroy(this.gameObject);
  118. });
  119. }
  120. private void OnDestroy()
  121. {
  122. if(closeBack != null)
  123. {
  124. closeBack.Invoke();
  125. }
  126. }
  127. }
  128. }