PopUpInfo.cs 4.7 KB

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