CommonMethod.cs 11 KB

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