123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- using LitJson;
- using SC.XR.Unity.Module_InputSystem;
- using ShadowStudio.Model;
- using ShadowStudio.Tool;
- using ShadowStudio.UI;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using Newtonsoft.Json;
- namespace XRTool.Util
- {
- /// <summary>
- /// 通用方法
- /// </summary>
- public static class CommonMethod
- {
- public static GameObject TusiObj;
- public static string tempToken;
- public static GameObject Loading;
- public static GameObject ScanEffect;
- public static List<int> scenes = new List<int>();
- public static List<UserAvatar> UserAvatarsList = new List<UserAvatar>();
- public static int currentScene;
- public static string selfHomepeerId;
- public static string roomPassWord;
- public static bool IsReceive;
- /// <summary>
- /// 获取当前本地时间戳
- /// </summary>
- /// <returns></returns>
- public static long GetCurrentTimeUnix()
- {
- TimeSpan cha = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)));
- long t = (long)cha.TotalSeconds;
-
- return t;
- }
- /// <summary>
- /// 获取当前本地时间戳(毫秒级 13位)
- /// </summary>
- /// <returns></returns>
- public static long GetCurrentTimeUnixMilliseconds()
- {
- TimeSpan cha = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)));
- long t = (long)cha.TotalMilliseconds;
- return t;
- }
- /// <summary>
- /// 实例化二级弹窗
- /// </summary>
- //public static GameObject InstanceDlg(string path)
- //{
- // var dlg = Resources.Load(path);
- // if (dlg)
- // {
- // GameObject obj = GameObject.Instantiate(dlg) as GameObject;
- // GameNode.Instance.SetParent(ObjNode.WorldCanvas, obj.transform, new Vector3(0, 0, 0.45f), Vector3.zero, new Vector3(0.001f, 0.001f, 0.001f));
- // return obj;
- // }
- // return null;
- //}
- /// <summary>
- /// 实例化扫描特效
- /// </summary>
- public static GameObject InstanceScanEffect()
- {
- var dlg = Resources.Load("currency_saomiao");
- if (dlg)
- {
- GameObject obj = GameObject.Instantiate(dlg) as GameObject;
- if (GSXRManager.Instance.IsRunning)
- {
- obj.transform.SetParent(GSXRManager.Instance.head, false);
- obj.transform.localPosition = new Vector3(0f, 0.01f, 1.7f);
- obj.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
- }
- return obj;
- }
- return null;
- }
- public static void ShowScanEffect(bool isshow)
- {
- if (!ScanEffect)
- {
- ScanEffect = InstanceScanEffect();
- }
- if (isshow)
- {
- ScanEffect.SetActive(true);
- }
- else
- {
- ScanEffect.SetActive(false);
- }
- }
- /// <summary>
- /// 实例化吐司弹窗
- /// </summary>
- public static GameObject InstanceTusi()
- {
- var dlg = Resources.Load("Pop/TuSi");
- if (dlg)
- {
- GameObject obj = GameObject.Instantiate(dlg) as GameObject;
- //GameNode.Instance.SetParent(ObjNode.WorldCanvas, obj.transform, new Vector3(0, 0, 0.45f), Vector3.zero, new Vector3(0.001f, 0.001f, 0.001f));
- return obj;
- }
- return null;
- }
- public static void ShowTextTusi()
- {
- if (TusiObj)
- {
- TusiObj.SetActive(true);
- }
- else
- {
- TusiObj = InstanceTusi();
- }
- }
- private static AsyncOperation async;
- public static void LoadSence(string senceName)
- {
- async = SceneManager.LoadSceneAsync(senceName);
- async.allowSceneActivation = false;
- }
- public static void AllowLoadSence()
- {
- async.allowSceneActivation = true;
- }
- public static void ShowLoading()
- {
- if (GSXRManager.Instance != null)
- {
- if (Loading == null)
- {
- Loading = (GameObject)Resources.Load("loading");
- Loading = GameObject.Instantiate(Loading);
- Loading.transform.parent = GSXRManager.Instance.head;
- Loading.transform.localPosition = new Vector3(0, 0, 1);
- Loading.transform.localEulerAngles = new Vector3(0, 0, 0);
- Loading.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
- }
- Loading.SetActive(false);
- SCInputModule.Instance.CanProcessEvent = false;
- }
- }
- public static void HideLoading()
- {
- SCInputModule.Instance.CanProcessEvent = true;
- if (Loading != null)
- {
- Loading.SetActive(false);
- }
- }
- public static float delayTime=0.3f;
- public static Queue<string> queueList =new Queue<string>();
- public static Timer timeQueue;
- public static GameObject NetLoading;
- public static Timer timeEndQueue;
- public static void ShowNetLoading(string str,string message)
- {
- SCInputModule.Instance.CanProcessEvent = false;
- if (queueList.Count <= 0)
- {
- UnityLog.Log("开始通讯", 3);
- // SCInputModule.Instance.CanProcessEvent = false;
- timeQueue = TimerMgr.Instance.CreateTimer(() => {
- if(timeEndQueue!=null)
- {
- TimerMgr.Instance.DestroyTimer(timeEndQueue);
- timeEndQueue = null;
- }
- if (NetLoading == null)
- {
- NetLoading = (GameObject)Resources.Load("loading");
- NetLoading = GameObject.Instantiate(NetLoading);
- NetLoading.transform.parent = OpenXRCamera.Instance.head;
- NetLoading.transform.localPosition = new Vector3(0, 0, 1);
- NetLoading.transform.localEulerAngles = new Vector3(0, 0, 0);
- NetLoading.transform.localScale = new Vector3(0.5f, 0.5f, delayTime);
- }
- NetLoading.GetComponentInChildren<TextMesh>().text = message;
- NetLoading.SetActive(true);
- timeQueue = null;
- }, 0.5f);
- }
- UnityLog.Log("增加通讯" + queueList.Count, 3);
- queueList.Enqueue(str);
- }
- public static ArtType getArtType(int type)
- {
- switch (type)
- {
- case 0:
- return ArtType.Model;
- case 1:
- return ArtType.Image;
- case 2:
- return ArtType.Audio;
- case 3:
- return ArtType.Movies;
- case 4:
- return ArtType.Prefab;
- case 5:
- return ArtType.Model2D;
- case 6:
- return ArtType.WorldDlg;
- }
- return ArtType.Image;
- }
- public static InstaceType getInstaceType(int type)
- {
- switch (type)
- {
- case 0:
- return InstaceType.ExtralURLDownload;
- case 1:
- return InstaceType.UnityBase;
- case 2:
- return InstaceType.ResourceLoad;
- case 3:
- return InstaceType.LocalPath;
- case 4:
- return InstaceType.AssetBundle;
- case 5:
- return InstaceType.References;
- }
- return InstaceType.ResourceLoad;
- }
-
- public static List<ArtInfo> artList=new List<ArtInfo>();
- public static void getModelList()
- {
- // return;
- NetWorkHeaders.GetUrlmodel((JsonData data1) =>
- {
- //ResourcesManager.ArtServerPath = data1["data"]["url"].ToString();
- artList = new List<ArtInfo>();
- for (int i = 0; i < 7; i++)
- {
- NetWorkHeaders.GetOtherModel(i.ToString(), (JsonData data) => {
- for (int j = 0; j < data["data"].Count; j++)
- {
- ArtInfo artinfo = new ArtInfo();
- artinfo.ArtId = data["data"][j]["art_id"].ToString();
- artinfo.ArtName = data["data"][j]["art_name"].ToString();
- artinfo.InstaceType = getInstaceType(int.Parse(data["data"][j]["instace_type"].ToString()));
-
- artinfo.Url = data["data"][j]["url"].ToString();
- artinfo.Icon = data["data"][j]["icon"].ToString();
- artinfo.ArtType = getArtType(int.Parse(data["data"][j]["art_type"].ToString()));
- artinfo.Version = data["data"][j]["version"].ToString();
- artinfo.Distance = float.Parse(data["data"][j]["distance"].ToString());
- artinfo.ContainerName = data["data"][j]["container_name"].ToString();
- artinfo.ImmediateSyn = data["data"][j]["immediate_syn"].ToString() == "0" ? false : true;
- artinfo.Component = data["data"][j]["component"].ToString();
- artinfo.Description = data["data"][j]["description"].ToString();
- artList.Add(artinfo);
- Debug.Log(data["data"][j].ToJson());
- }
- });
- }
- });
-
- }
- public static void HideNetLoading(string str)
- {
- UnityLog.Log("减少通讯" + str, 3);
- if (queueList.Count > 0)
- {
- UnityLog.Log("减少通讯"+ queueList.Count, 3);
- queueList.Dequeue();
- if (queueList.Count <= 0)
- {
- UnityLog.Log("通讯结束" + queueList.Count, 3);
- SCInputModule.Instance.CanProcessEvent = true;
- if (timeQueue != null)
- {
- TimerMgr.Instance.DestroyTimer(timeQueue);
- }
- if (NetLoading != null && NetLoading.activeSelf)
- {
- timeEndQueue = TimerMgr.Instance.CreateTimer(() =>
- {
- NetLoading.SetActive(false);
- }, 0.5f);
- }
- // SCInputModule.Instance.CanProcessEvent = true;
- }
- }
- }
- }
- }
|