CommonMethod.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. using LitJson;
  2. using SC.XR.Unity.Module_InputSystem;
  3. using ShadowStudio.Model;
  4. using ShadowStudio.Tool;
  5. using ShadowStudio.UI;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using UnityEngine;
  10. using UnityEngine.SceneManagement;
  11. using Newtonsoft.Json;
  12. namespace XRTool.Util
  13. {
  14. /// <summary>
  15. /// 通用方法
  16. /// </summary>
  17. public static class CommonMethod
  18. {
  19. public static GameObject TusiObj;
  20. public static string tempToken;
  21. public static GameObject Loading;
  22. public static GameObject ScanEffect;
  23. public static List<int> scenes = new List<int>();
  24. public static List<UserAvatar> UserAvatarsList = new List<UserAvatar>();
  25. public static int currentScene;
  26. public static string selfHomepeerId;
  27. public static string roomPassWord;
  28. public static bool IsReceive;
  29. /// <summary>
  30. /// 获取当前本地时间戳
  31. /// </summary>
  32. /// <returns></returns>
  33. public static long GetCurrentTimeUnix()
  34. {
  35. TimeSpan cha = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)));
  36. long t = (long)cha.TotalSeconds;
  37. return t;
  38. }
  39. /// <summary>
  40. /// 获取当前本地时间戳(毫秒级 13位)
  41. /// </summary>
  42. /// <returns></returns>
  43. public static long GetCurrentTimeUnixMilliseconds()
  44. {
  45. TimeSpan cha = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)));
  46. long t = (long)cha.TotalMilliseconds;
  47. return t;
  48. }
  49. /// <summary>
  50. /// 实例化二级弹窗
  51. /// </summary>
  52. //public static GameObject InstanceDlg(string path)
  53. //{
  54. // var dlg = Resources.Load(path);
  55. // if (dlg)
  56. // {
  57. // GameObject obj = GameObject.Instantiate(dlg) as GameObject;
  58. // GameNode.Instance.SetParent(ObjNode.WorldCanvas, obj.transform, new Vector3(0, 0, 0.45f), Vector3.zero, new Vector3(0.001f, 0.001f, 0.001f));
  59. // return obj;
  60. // }
  61. // return null;
  62. //}
  63. /// <summary>
  64. /// 实例化扫描特效
  65. /// </summary>
  66. public static GameObject InstanceScanEffect()
  67. {
  68. var dlg = Resources.Load("currency_saomiao");
  69. if (dlg)
  70. {
  71. GameObject obj = GameObject.Instantiate(dlg) as GameObject;
  72. if (GSXRManager.Instance.IsRunning)
  73. {
  74. obj.transform.SetParent(GSXRManager.Instance.head, false);
  75. obj.transform.localPosition = new Vector3(0f, 0.01f, 1.7f);
  76. obj.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
  77. }
  78. return obj;
  79. }
  80. return null;
  81. }
  82. public static void ShowScanEffect(bool isshow)
  83. {
  84. if (!ScanEffect)
  85. {
  86. ScanEffect = InstanceScanEffect();
  87. }
  88. if (isshow)
  89. {
  90. ScanEffect.SetActive(true);
  91. }
  92. else
  93. {
  94. ScanEffect.SetActive(false);
  95. }
  96. }
  97. /// <summary>
  98. /// 实例化吐司弹窗
  99. /// </summary>
  100. public static GameObject InstanceTusi()
  101. {
  102. var dlg = Resources.Load("Pop/TuSi");
  103. if (dlg)
  104. {
  105. GameObject obj = GameObject.Instantiate(dlg) as GameObject;
  106. //GameNode.Instance.SetParent(ObjNode.WorldCanvas, obj.transform, new Vector3(0, 0, 0.45f), Vector3.zero, new Vector3(0.001f, 0.001f, 0.001f));
  107. return obj;
  108. }
  109. return null;
  110. }
  111. public static void ShowTextTusi()
  112. {
  113. if (TusiObj)
  114. {
  115. TusiObj.SetActive(true);
  116. }
  117. else
  118. {
  119. TusiObj = InstanceTusi();
  120. }
  121. }
  122. private static AsyncOperation async;
  123. public static void LoadSence(string senceName)
  124. {
  125. async = SceneManager.LoadSceneAsync(senceName);
  126. async.allowSceneActivation = false;
  127. }
  128. public static void AllowLoadSence()
  129. {
  130. async.allowSceneActivation = true;
  131. }
  132. public static void ShowLoading()
  133. {
  134. if (GSXRManager.Instance != null)
  135. {
  136. if (Loading == null)
  137. {
  138. Loading = (GameObject)Resources.Load("loading");
  139. Loading = GameObject.Instantiate(Loading);
  140. Loading.transform.parent = GSXRManager.Instance.head;
  141. Loading.transform.localPosition = new Vector3(0, 0, 1);
  142. Loading.transform.localEulerAngles = new Vector3(0, 0, 0);
  143. Loading.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
  144. }
  145. Loading.SetActive(false);
  146. SCInputModule.Instance.CanProcessEvent = false;
  147. }
  148. }
  149. public static void HideLoading()
  150. {
  151. SCInputModule.Instance.CanProcessEvent = true;
  152. if (Loading != null)
  153. {
  154. Loading.SetActive(false);
  155. }
  156. }
  157. public static float delayTime=0.3f;
  158. public static Queue<string> queueList =new Queue<string>();
  159. public static Timer timeQueue;
  160. public static GameObject NetLoading;
  161. public static Timer timeEndQueue;
  162. public static void ShowNetLoading(string str,string message)
  163. {
  164. SCInputModule.Instance.CanProcessEvent = false;
  165. if (queueList.Count <= 0)
  166. {
  167. UnityLog.Log("开始通讯", 3);
  168. // SCInputModule.Instance.CanProcessEvent = false;
  169. timeQueue = TimerMgr.Instance.CreateTimer(() => {
  170. if(timeEndQueue!=null)
  171. {
  172. TimerMgr.Instance.DestroyTimer(timeEndQueue);
  173. timeEndQueue = null;
  174. }
  175. if (NetLoading == null)
  176. {
  177. NetLoading = (GameObject)Resources.Load("loading");
  178. NetLoading = GameObject.Instantiate(NetLoading);
  179. NetLoading.transform.parent = OpenXRCamera.Instance.head;
  180. NetLoading.transform.localPosition = new Vector3(0, 0, 1);
  181. NetLoading.transform.localEulerAngles = new Vector3(0, 0, 0);
  182. NetLoading.transform.localScale = new Vector3(0.5f, 0.5f, delayTime);
  183. }
  184. NetLoading.GetComponentInChildren<TextMesh>().text = message;
  185. NetLoading.SetActive(true);
  186. timeQueue = null;
  187. }, 0.5f);
  188. }
  189. UnityLog.Log("增加通讯" + queueList.Count, 3);
  190. queueList.Enqueue(str);
  191. }
  192. public static ArtType getArtType(int type)
  193. {
  194. switch (type)
  195. {
  196. case 0:
  197. return ArtType.Model;
  198. case 1:
  199. return ArtType.Image;
  200. case 2:
  201. return ArtType.Audio;
  202. case 3:
  203. return ArtType.Movies;
  204. case 4:
  205. return ArtType.Prefab;
  206. case 5:
  207. return ArtType.Model2D;
  208. case 6:
  209. return ArtType.WorldDlg;
  210. }
  211. return ArtType.Image;
  212. }
  213. public static InstaceType getInstaceType(int type)
  214. {
  215. switch (type)
  216. {
  217. case 0:
  218. return InstaceType.ExtralURLDownload;
  219. case 1:
  220. return InstaceType.UnityBase;
  221. case 2:
  222. return InstaceType.ResourceLoad;
  223. case 3:
  224. return InstaceType.LocalPath;
  225. case 4:
  226. return InstaceType.AssetBundle;
  227. case 5:
  228. return InstaceType.References;
  229. }
  230. return InstaceType.ResourceLoad;
  231. }
  232. public static List<ArtInfo> artList=new List<ArtInfo>();
  233. public static void getModelList()
  234. {
  235. // return;
  236. NetWorkHeaders.GetUrlmodel((JsonData data1) =>
  237. {
  238. //ResourcesManager.ArtServerPath = data1["data"]["url"].ToString();
  239. artList = new List<ArtInfo>();
  240. for (int i = 0; i < 7; i++)
  241. {
  242. NetWorkHeaders.GetOtherModel(i.ToString(), (JsonData data) => {
  243. for (int j = 0; j < data["data"].Count; j++)
  244. {
  245. ArtInfo artinfo = new ArtInfo();
  246. artinfo.ArtId = data["data"][j]["art_id"].ToString();
  247. artinfo.ArtName = data["data"][j]["art_name"].ToString();
  248. artinfo.InstaceType = getInstaceType(int.Parse(data["data"][j]["instace_type"].ToString()));
  249. artinfo.Url = data["data"][j]["url"].ToString();
  250. artinfo.Icon = data["data"][j]["icon"].ToString();
  251. artinfo.ArtType = getArtType(int.Parse(data["data"][j]["art_type"].ToString()));
  252. artinfo.Version = data["data"][j]["version"].ToString();
  253. artinfo.Distance = float.Parse(data["data"][j]["distance"].ToString());
  254. artinfo.ContainerName = data["data"][j]["container_name"].ToString();
  255. artinfo.ImmediateSyn = data["data"][j]["immediate_syn"].ToString() == "0" ? false : true;
  256. artinfo.Component = data["data"][j]["component"].ToString();
  257. artinfo.Description = data["data"][j]["description"].ToString();
  258. artList.Add(artinfo);
  259. Debug.Log(data["data"][j].ToJson());
  260. }
  261. });
  262. }
  263. });
  264. }
  265. public static void HideNetLoading(string str)
  266. {
  267. UnityLog.Log("减少通讯" + str, 3);
  268. if (queueList.Count > 0)
  269. {
  270. UnityLog.Log("减少通讯"+ queueList.Count, 3);
  271. queueList.Dequeue();
  272. if (queueList.Count <= 0)
  273. {
  274. UnityLog.Log("通讯结束" + queueList.Count, 3);
  275. SCInputModule.Instance.CanProcessEvent = true;
  276. if (timeQueue != null)
  277. {
  278. TimerMgr.Instance.DestroyTimer(timeQueue);
  279. }
  280. if (NetLoading != null && NetLoading.activeSelf)
  281. {
  282. timeEndQueue = TimerMgr.Instance.CreateTimer(() =>
  283. {
  284. NetLoading.SetActive(false);
  285. }, 0.5f);
  286. }
  287. // SCInputModule.Instance.CanProcessEvent = true;
  288. }
  289. }
  290. }
  291. }
  292. }