PopUpInfo.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using SC.XR.Unity;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. using XRTool.Util;
  8. using TMPro;
  9. public class PopUpInfo : RemoteSingleton<PopUpInfo>
  10. {
  11. public GameObject NetErrorPanel;
  12. public enum PopType
  13. {
  14. Tip=1,
  15. Pop = 2,
  16. PopOk = 3,
  17. ListenDlg=4
  18. }
  19. public void Start()
  20. {
  21. NetErrorPanel.SetActive(false);
  22. Tip.SetActive(false);
  23. Pop.SetActive(false);
  24. PopOk.SetActive(false);
  25. ListenDlg.SetActive(false);
  26. }
  27. public GameObject Tip;
  28. public GameObject Pop;
  29. public GameObject PopOk;
  30. public GameObject ListenDlg;
  31. private PopType pType;
  32. public void showPublic(PopType popType)
  33. {
  34. pType = popType;
  35. switch (popType)
  36. {
  37. case PopType.Tip:
  38. showTip();
  39. break;
  40. case PopType.Pop:
  41. showPop();
  42. break;
  43. case PopType.PopOk:
  44. showPopOk();
  45. break;
  46. case PopType.ListenDlg:
  47. showListenDlg();
  48. break;
  49. }
  50. }
  51. public void showPublic(PopType popType,string msg, string b1 = "确定", Action ok = null, string b2 = "取消", Action cancel = null)
  52. {
  53. btn1OK.onClick.RemoveAllListeners();
  54. btn2Cancel.onClick.RemoveAllListeners();
  55. pType = popType;
  56. msgText.text = msg;
  57. btn1Text.text = b1;
  58. btn2Text.text = b2;
  59. btn1OK.onClick.AddListener(() => {
  60. close();
  61. if (ok!=null)
  62. ok.Invoke();
  63. }
  64. );
  65. btn2Cancel.onClick.AddListener(() => {
  66. close();
  67. if (cancel!=null)
  68. cancel.Invoke();
  69. });
  70. switch (popType)
  71. {
  72. case PopType.Tip:
  73. showTip();
  74. break;
  75. case PopType.Pop:
  76. showPop();
  77. break;
  78. case PopType.PopOk:
  79. showPopOk();
  80. break;
  81. }
  82. }
  83. private TMP_Text msgText
  84. {
  85. get
  86. {
  87. switch (pType)
  88. {
  89. case PopType.Tip:
  90. return UnityUtil.GetDepthChild<TMP_Text>(Tip.transform, "msgText");
  91. case PopType.Pop:
  92. return UnityUtil.GetDepthChild<TMP_Text>(Pop.transform, "msgText");
  93. case PopType.PopOk:
  94. return UnityUtil.GetDepthChild<TMP_Text>(PopOk.transform, "msgText");
  95. }
  96. return null;
  97. }
  98. }
  99. private TMP_Text btn1Text
  100. {
  101. get
  102. {
  103. switch (pType)
  104. {
  105. case PopType.Pop:
  106. return UnityUtil.GetDepthChild<TMP_Text>(Pop.transform, "btn1Text");
  107. case PopType.PopOk:
  108. return UnityUtil.GetDepthChild<TMP_Text>(PopOk.transform, "btn1Text");
  109. }
  110. return UnityUtil.GetDepthChild<TMP_Text>(Pop.transform, "btn1Text");
  111. }
  112. }
  113. private TMP_Text btn2Text
  114. {
  115. get
  116. {
  117. return UnityUtil.GetDepthChild<TMP_Text>(Pop.transform, "btn2Text");
  118. }
  119. }
  120. private Button btn1OK
  121. {
  122. get
  123. {
  124. switch (pType)
  125. {
  126. case PopType.Pop:
  127. return UnityUtil.GetDepthChild<Button>(Pop.transform, "btn1OK");
  128. case PopType.PopOk:
  129. return UnityUtil.GetDepthChild<Button>(PopOk.transform, "btn1OK");
  130. }
  131. return UnityUtil.GetDepthChild<Button>(Pop.transform, "btn1OK");
  132. }
  133. }
  134. private Button btn2Cancel
  135. {
  136. get
  137. {
  138. return UnityUtil.GetDepthChild<Button>(Pop.transform, "btn2Cancel");
  139. }
  140. }
  141. public void close()
  142. {
  143. Tip.SetActive(false);
  144. Pop.SetActive(false);
  145. PopOk.SetActive(false);
  146. }
  147. public void showTip()
  148. {
  149. Tip.SetActive(true);
  150. Pop.SetActive(false);
  151. PopOk.SetActive(false);
  152. ListenDlg.SetActive(false);
  153. TimerMgr.Instance.CreateTimer(()=> { Tip.SetActive(false); },2f);
  154. }
  155. public void showPop()
  156. {
  157. Tip.SetActive(false);
  158. PopOk.SetActive(false);
  159. Pop.SetActive(true);
  160. ListenDlg.SetActive(false);
  161. }
  162. public void showPopOk()
  163. {
  164. Tip.SetActive(false);
  165. Pop.SetActive(false);
  166. PopOk.SetActive(true);
  167. ListenDlg.SetActive(false);
  168. }
  169. public void showListenDlg()
  170. {
  171. Tip.SetActive(false);
  172. Pop.SetActive(false);
  173. PopOk.SetActive(false);
  174. ListenDlg.SetActive(true);
  175. }
  176. public void ShowNetErrorPanel()
  177. {
  178. NetErrorPanel.SetActive(true);
  179. }
  180. public void HideNetErrorPanel()
  181. {
  182. NetErrorPanel.SetActive(false);
  183. }
  184. }