123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- using BeinLab.Util;
- 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;
- using ShadowStudio.Mgr;
- namespace XRTool.Util
- {
- /// <summary>
- /// 通用方法
- /// </summary>
- public static class CommonMethod
- {
- public static bool isZiDong = false;
- public static GameObject TusiObj;
- public static string tempToken;
- public static GameObject Loading;
- public static GameObject ScanEffect;
- public static List<GoodsInfo> GoodsInfoList = new List<GoodsInfo>();
- public static List<Peer> PeerList = new List<Peer>();
- public static List<SceneConfig> scenes = new List<SceneConfig>();
- public static List<UserAvatar> UserAvatarsList = new List<UserAvatar>();
- public static SceneConfig currentScene;
- public static string selfHomepeerId;
- public static string roomPassWord;
- //被替换的代码
- //public static RoomConfig roomConfig;
- public static RoomConfig roomConfig;
- public static Peer MyPeer;
- public static bool IsReceive;
- public static MySetting mySetting;
- public static Peer SelfPeer(string peerId, string nickName)
- {
- if (MyPeer == null)
- {
- MyPeer = new Peer();
- }
- MyPeer.PeerId = peerId;
- MyPeer.NickName = nickName;
- if (!string.IsNullOrEmpty(UserInfoMgr.Instance.userConfig.Avatar))
- {
- MyPeer.Avatar = UserInfoMgr.Instance.userConfig.Avatar;
- }
- Debug.Log(peerId);
- // AgoraVideoAudioManager.Instance.RegisterLocalUserAccount(peerId);
- return MyPeer;
- }
- /// <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>
- /// 实例化二级弹窗
- /// </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 (true)
- {
- obj.transform.SetParent(OpenXRCamera.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();
- }
- }
- /// <summary>
- /// 显示弹窗
- /// </summary>
- 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)
- {
- GameObject gameobject = InstanceDlg("Pop/BasePop");
- BasePop pop = gameobject.GetComponent<BasePop>();
- pop.popType = type;
- pop.callBack1 = callBack1;
- pop.btnText1 = text1;
- pop.btnText2 = text2;
- pop.callBack2 = callBack2;
- pop.title = title;
- pop.msg = msg;
- pop.ifneedInput = ifneedInput;
- pop.callBack3 = callBack3;
- pop.init();
- if (ifneedInput)
- {
- followCamera follow = gameobject.GetComponent<followCamera>();
- if (follow)
- {
- follow._dicCount = 0.43f;
- }
- }
- return gameobject;
- }
- /// <summary>
- /// 显示顶号登录界面
- /// </summary>
- public static void ShowLoginAbnormalPop()
- {
- ShowPopUp(PopType.Cancel, LanguageMgr.Instance.GetMessage("1059").Message, LanguageMgr.Instance.GetMessage("1057").Message, () =>
- {
- LoginDlg.Instance.ClickBreakLoginBtn();
- }, LanguageMgr.Instance.GetMessage("1066").Message, null,
- LanguageMgr.Instance.GetMessage("1058").Message);//匿名函数()=>{} 当有()是参数的回调方法已经不为空
- }
- /// <summary>
- /// 显示强制退出弹窗
- /// </summary>
- public static void ShowLoginAbnormalOutPop()
- {
- WSHandler.roomCloes();
- WSHandler.clientClosed();
- ShowPopUp(PopType.Normal, LanguageMgr.Instance.GetMessage("1059").Message, LanguageMgr.Instance.GetMessage("1060").Message, () =>
- { LoadLoginSence(); }, LanguageMgr.Instance.GetMessage("1066").Message);
- }
- public static void ShowNetErrorAbnormalOutPop()
- {
- WSHandler.roomCloes();
- WSHandler.clientClosed();
- ShowPopUp(PopType.Normal, LanguageMgr.Instance.GetMessage("1067").Message, LanguageMgr.Instance.GetMessage("1062").Message, () =>
- { LoadLoginSence(); }, LanguageMgr.Instance.GetMessage("1066").Message);
- }
- /// <summary>
- /// 显示无网络弹窗
- /// </summary>
- public static GameObject ShowNetworkAnomalyPop(Action callBack)
- {
- return ShowPopUp(PopType.Normal, LanguageMgr.Instance.GetMessage("1067").Message, LanguageMgr.Instance.GetMessage("1062").Message, () =>
- {
- callBack.Invoke();
- }, LanguageMgr.Instance.GetMessage("1066").Message);
- }
- public static void LoadLoginSence()
- {
- if (BoardDlg.Instance != null)
- {
- BoardDlg.Instance.DestoryARcamera();
- }
- SceneManager.LoadScene("Login");
- }
- 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()
- {
- if (Loading != null)
- {
- Loading.SetActive(false);
- }
- SCInputModule.Instance.CanProcessEvent = true;
- }
- 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)
- {
- if (queueList.Count <= 0)
- {
- UnityLog.Instance.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.Instance.Log("增加通讯" + queueList.Count, 3);
- queueList.Enqueue(str);
- }
- public static List<ArtInfo> artList = new List<ArtInfo>();
- /// <summary>
- /// 资源列表信息赋值
- /// </summary>
- /// <param name="artInfoList"></param>
- public static void SetArtInfoList(List<ArtInfo> artInfoList)
- {
- //artList.Clear();
- artList.AddRange(artInfoList);
- }
- public static bool isLookRoom()
- {
- if (CommonMethod.roomConfig == null)
- {
- return false;
- }
- if (!(CommonMethod.roomConfig.Room_type == "1" && CommonMethod.roomConfig.Is_created == "0"))
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- public static void HideNetLoading(string str)
- {
- UnityLog.Instance.Log("减少通讯" + str, 3);
- if (queueList.Count > 0)
- {
- UnityLog.Instance.Log("减少通讯" + queueList.Count, 3);
- queueList.Dequeue();
- if (queueList.Count <= 0)
- {
- UnityLog.Instance.Log("通讯结束" + queueList.Count, 3);
- 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;
- }
- }
- }
- }
- }
|