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
{
///
/// 通用方法
///
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 GoodsInfoList = new List();
public static List PeerList = new List();
public static List scenes = new List();
public static List UserAvatarsList = new List();
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;
}
///
/// 获取当前本地时间戳
///
///
public static long GetCurrentTimeUnix()
{
TimeSpan cha = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)));
long t = (long)cha.TotalSeconds;
return t;
}
///
/// 实例化二级弹窗
///
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;
}
///
/// 实例化扫描特效
///
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);
}
}
///
/// 实例化吐司弹窗
///
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();
}
}
///
/// 显示弹窗
///
public static GameObject ShowPopUp(PopType type, string title = "", string msg = "", Action callBack1 = null, string text1 = "确 定", Action callBack2 = null, string text2 = "取 消", bool ifneedInput = false, Action callBack3 = null)
{
GameObject gameobject = InstanceDlg("Pop/BasePop");
BasePop pop = gameobject.GetComponent();
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();
if (follow)
{
follow._dicCount = 0.43f;
}
}
return gameobject;
}
///
/// 显示顶号登录界面
///
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);//匿名函数()=>{} 当有()是参数的回调方法已经不为空
}
///
/// 显示强制退出弹窗
///
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);
}
///
/// 显示无网络弹窗
///
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 queueList = new Queue();
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().text = message;
NetLoading.SetActive(true);
timeQueue = null;
}, 0.5f);
}
UnityLog.Instance.Log("增加通讯" + queueList.Count, 3);
queueList.Enqueue(str);
}
public static List artList = new List();
///
/// 资源列表信息赋值
///
///
public static void SetArtInfoList(List 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;
}
}
}
}
}