CommonMethod.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. using BeinLab.Util;
  2. using LitJson;
  3. using SC.XR.Unity.Module_InputSystem;
  4. using ShadowStudio.Model;
  5. using ShadowStudio.Tool;
  6. using ShadowStudio.UI;
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using UnityEngine;
  11. using UnityEngine.SceneManagement;
  12. using Newtonsoft.Json;
  13. using ShadowStudio.Mgr;
  14. namespace XRTool.Util
  15. {
  16. /// <summary>
  17. /// 通用方法
  18. /// </summary>
  19. public static class CommonMethod
  20. {
  21. public static bool isZiDong = false;
  22. public static GameObject TusiObj;
  23. public static string tempToken;
  24. public static GameObject Loading;
  25. public static GameObject ScanEffect;
  26. public static List<GoodsInfo> GoodsInfoList = new List<GoodsInfo>();
  27. public static List<Peer> PeerList = new List<Peer>();
  28. public static List<SceneConfig> scenes = new List<SceneConfig>();
  29. public static List<UserAvatar> UserAvatarsList = new List<UserAvatar>();
  30. public static SceneConfig currentScene;
  31. public static string selfHomepeerId;
  32. public static string roomPassWord;
  33. //被替换的代码
  34. //public static RoomConfig roomConfig;
  35. public static RoomConfig roomConfig;
  36. public static Peer MyPeer;
  37. public static bool IsReceive;
  38. public static MySetting mySetting;
  39. public static Peer SelfPeer(string peerId, string nickName)
  40. {
  41. if (MyPeer == null)
  42. {
  43. MyPeer = new Peer();
  44. }
  45. MyPeer.PeerId = peerId;
  46. MyPeer.NickName = nickName;
  47. if (!string.IsNullOrEmpty(UserInfoMgr.Instance.userConfig.Avatar))
  48. {
  49. MyPeer.Avatar = UserInfoMgr.Instance.userConfig.Avatar;
  50. }
  51. Debug.Log(peerId);
  52. // AgoraVideoAudioManager.Instance.RegisterLocalUserAccount(peerId);
  53. return MyPeer;
  54. }
  55. /// <summary>
  56. /// 获取当前本地时间戳
  57. /// </summary>
  58. /// <returns></returns>
  59. public static long GetCurrentTimeUnix()
  60. {
  61. TimeSpan cha = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)));
  62. long t = (long)cha.TotalSeconds;
  63. return t;
  64. }
  65. /// <summary>
  66. /// 实例化二级弹窗
  67. /// </summary>
  68. public static GameObject InstanceDlg(string path)
  69. {
  70. var dlg = Resources.Load(path);
  71. if (dlg)
  72. {
  73. GameObject obj = GameObject.Instantiate(dlg) as GameObject;
  74. GameNode.Instance.SetParent(ObjNode.WorldCanvas, obj.transform, new Vector3(0, 0, 0.45f), Vector3.zero, new Vector3(0.001f, 0.001f, 0.001f));
  75. return obj;
  76. }
  77. return null;
  78. }
  79. /// <summary>
  80. /// 实例化扫描特效
  81. /// </summary>
  82. public static GameObject InstanceScanEffect()
  83. {
  84. var dlg = Resources.Load("currency_saomiao");
  85. if (dlg)
  86. {
  87. GameObject obj = GameObject.Instantiate(dlg) as GameObject;
  88. if (true)
  89. {
  90. obj.transform.SetParent(OpenXRCamera.Instance.head, false);
  91. obj.transform.localPosition = new Vector3(0f, 0.01f, 1.7f);
  92. obj.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
  93. }
  94. return obj;
  95. }
  96. return null;
  97. }
  98. public static void ShowScanEffect(bool isshow)
  99. {
  100. if (!ScanEffect)
  101. {
  102. ScanEffect = InstanceScanEffect();
  103. }
  104. if (isshow)
  105. {
  106. ScanEffect.SetActive(true);
  107. }
  108. else
  109. {
  110. ScanEffect.SetActive(false);
  111. }
  112. }
  113. /// <summary>
  114. /// 实例化吐司弹窗
  115. /// </summary>
  116. public static GameObject InstanceTusi()
  117. {
  118. var dlg = Resources.Load("Pop/TuSi");
  119. if (dlg)
  120. {
  121. GameObject obj = GameObject.Instantiate(dlg) as GameObject;
  122. GameNode.Instance.SetParent(ObjNode.WorldCanvas, obj.transform, new Vector3(0, 0, 0.45f), Vector3.zero, new Vector3(0.001f, 0.001f, 0.001f));
  123. return obj;
  124. }
  125. return null;
  126. }
  127. public static void ShowTextTusi()
  128. {
  129. if (TusiObj)
  130. {
  131. TusiObj.SetActive(true);
  132. }
  133. else
  134. {
  135. TusiObj = InstanceTusi();
  136. }
  137. }
  138. /// <summary>
  139. /// 显示弹窗
  140. /// </summary>
  141. public static GameObject ShowPopUp(PopType type, string title = "", string msg = "", Action callBack1 = null, string text1 = "确 定", Action callBack2 = null, string text2 = "取 消", bool ifneedInput = false, Action<string> callBack3 = null)
  142. {
  143. GameObject gameobject = InstanceDlg("Pop/BasePop");
  144. BasePop pop = gameobject.GetComponent<BasePop>();
  145. pop.popType = type;
  146. pop.callBack1 = callBack1;
  147. pop.btnText1 = text1;
  148. pop.btnText2 = text2;
  149. pop.callBack2 = callBack2;
  150. pop.title = title;
  151. pop.msg = msg;
  152. pop.ifneedInput = ifneedInput;
  153. pop.callBack3 = callBack3;
  154. pop.init();
  155. if (ifneedInput)
  156. {
  157. followCamera follow = gameobject.GetComponent<followCamera>();
  158. if (follow)
  159. {
  160. follow._dicCount = 0.43f;
  161. }
  162. }
  163. return gameobject;
  164. }
  165. /// <summary>
  166. /// 显示顶号登录界面
  167. /// </summary>
  168. public static void ShowLoginAbnormalPop()
  169. {
  170. ShowPopUp(PopType.Cancel, LanguageMgr.Instance.GetMessage("1059").Message, LanguageMgr.Instance.GetMessage("1057").Message, () =>
  171. {
  172. LoginDlg.Instance.ClickBreakLoginBtn();
  173. }, LanguageMgr.Instance.GetMessage("1066").Message, null,
  174. LanguageMgr.Instance.GetMessage("1058").Message);//匿名函数()=>{} 当有()是参数的回调方法已经不为空
  175. }
  176. /// <summary>
  177. /// 显示强制退出弹窗
  178. /// </summary>
  179. public static void ShowLoginAbnormalOutPop()
  180. {
  181. WSHandler.roomCloes();
  182. WSHandler.clientClosed();
  183. ShowPopUp(PopType.Normal, LanguageMgr.Instance.GetMessage("1059").Message, LanguageMgr.Instance.GetMessage("1060").Message, () =>
  184. { LoadLoginSence(); }, LanguageMgr.Instance.GetMessage("1066").Message);
  185. }
  186. public static void ShowNetErrorAbnormalOutPop()
  187. {
  188. WSHandler.roomCloes();
  189. WSHandler.clientClosed();
  190. ShowPopUp(PopType.Normal, LanguageMgr.Instance.GetMessage("1067").Message, LanguageMgr.Instance.GetMessage("1062").Message, () =>
  191. { LoadLoginSence(); }, LanguageMgr.Instance.GetMessage("1066").Message);
  192. }
  193. /// <summary>
  194. /// 显示无网络弹窗
  195. /// </summary>
  196. public static GameObject ShowNetworkAnomalyPop(Action callBack)
  197. {
  198. return ShowPopUp(PopType.Normal, LanguageMgr.Instance.GetMessage("1067").Message, LanguageMgr.Instance.GetMessage("1062").Message, () =>
  199. {
  200. callBack.Invoke();
  201. }, LanguageMgr.Instance.GetMessage("1066").Message);
  202. }
  203. public static void LoadLoginSence()
  204. {
  205. if (BoardDlg.Instance != null)
  206. {
  207. BoardDlg.Instance.DestoryARcamera();
  208. }
  209. SceneManager.LoadScene("Login");
  210. }
  211. private static AsyncOperation async;
  212. public static void LoadSence(string senceName)
  213. {
  214. async = SceneManager.LoadSceneAsync(senceName);
  215. async.allowSceneActivation = false;
  216. }
  217. public static void AllowLoadSence()
  218. {
  219. async.allowSceneActivation = true;
  220. }
  221. public static void ShowLoading()
  222. {
  223. if (GSXRManager.Instance != null)
  224. {
  225. if (Loading == null)
  226. {
  227. Loading = (GameObject)Resources.Load("loading");
  228. Loading = GameObject.Instantiate(Loading);
  229. Loading.transform.parent = GSXRManager.Instance.head;
  230. Loading.transform.localPosition = new Vector3(0, 0, 1);
  231. Loading.transform.localEulerAngles = new Vector3(0, 0, 0);
  232. Loading.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
  233. }
  234. Loading.SetActive(false);
  235. SCInputModule.Instance.CanProcessEvent = false;
  236. }
  237. }
  238. public static void HideLoading()
  239. {
  240. if (Loading != null)
  241. {
  242. Loading.SetActive(false);
  243. }
  244. SCInputModule.Instance.CanProcessEvent = true;
  245. }
  246. public static float delayTime = 0.3f;
  247. public static Queue<string> queueList = new Queue<string>();
  248. public static Timer timeQueue;
  249. public static GameObject NetLoading;
  250. public static Timer timeEndQueue;
  251. public static void ShowNetLoading(string str, string message)
  252. {
  253. if (queueList.Count <= 0)
  254. {
  255. UnityLog.Instance.Log("开始通讯", 3);
  256. SCInputModule.Instance.CanProcessEvent = false;
  257. timeQueue = TimerMgr.Instance.CreateTimer(() =>
  258. {
  259. if (timeEndQueue != null)
  260. {
  261. TimerMgr.Instance.DestroyTimer(timeEndQueue);
  262. timeEndQueue = null;
  263. }
  264. if (NetLoading == null)
  265. {
  266. NetLoading = (GameObject)Resources.Load("loading");
  267. NetLoading = GameObject.Instantiate(NetLoading);
  268. NetLoading.transform.parent = OpenXRCamera.Instance.head;
  269. NetLoading.transform.localPosition = new Vector3(0, 0, 1);
  270. NetLoading.transform.localEulerAngles = new Vector3(0, 0, 0);
  271. NetLoading.transform.localScale = new Vector3(0.5f, 0.5f, delayTime);
  272. }
  273. NetLoading.GetComponentInChildren<TextMesh>().text = message;
  274. NetLoading.SetActive(true);
  275. timeQueue = null;
  276. }, 0.5f);
  277. }
  278. UnityLog.Instance.Log("增加通讯" + queueList.Count, 3);
  279. queueList.Enqueue(str);
  280. }
  281. public static List<ArtInfo> artList = new List<ArtInfo>();
  282. /// <summary>
  283. /// 资源列表信息赋值
  284. /// </summary>
  285. /// <param name="artInfoList"></param>
  286. public static void SetArtInfoList(List<ArtInfo> artInfoList)
  287. {
  288. //artList.Clear();
  289. artList.AddRange(artInfoList);
  290. }
  291. public static bool isLookRoom()
  292. {
  293. if (CommonMethod.roomConfig == null)
  294. {
  295. return false;
  296. }
  297. if (!(CommonMethod.roomConfig.Room_type == "1" && CommonMethod.roomConfig.Is_created == "0"))
  298. {
  299. return false;
  300. }
  301. else
  302. {
  303. return true;
  304. }
  305. }
  306. public static void HideNetLoading(string str)
  307. {
  308. UnityLog.Instance.Log("减少通讯" + str, 3);
  309. if (queueList.Count > 0)
  310. {
  311. UnityLog.Instance.Log("减少通讯" + queueList.Count, 3);
  312. queueList.Dequeue();
  313. if (queueList.Count <= 0)
  314. {
  315. UnityLog.Instance.Log("通讯结束" + queueList.Count, 3);
  316. if (timeQueue != null)
  317. {
  318. TimerMgr.Instance.DestroyTimer(timeQueue);
  319. }
  320. if (NetLoading != null && NetLoading.activeSelf)
  321. {
  322. timeEndQueue = TimerMgr.Instance.CreateTimer(() =>
  323. {
  324. NetLoading.SetActive(false);
  325. }, 0.5f);
  326. }
  327. SCInputModule.Instance.CanProcessEvent = true;
  328. }
  329. }
  330. }
  331. }
  332. }