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
{
///
/// 通用方法
///
public static class CommonMethod
{
public static GameObject TusiObj;
public static string tempToken;
public static GameObject Loading;
public static GameObject ScanEffect;
public static List scenes = new List();
public static List UserAvatarsList = new List();
public static int currentScene;
public static string selfHomepeerId;
public static string roomPassWord;
public static bool IsReceive;
///
/// 获取当前本地时间戳
///
///
public static long GetCurrentTimeUnix()
{
TimeSpan cha = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)));
long t = (long)cha.TotalSeconds;
return t;
}
///
/// 获取当前本地时间戳(毫秒级 13位)
///
///
public static long GetCurrentTimeUnixMilliseconds()
{
TimeSpan cha = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)));
long t = (long)cha.TotalMilliseconds;
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 (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);
}
}
///
/// 实例化吐司弹窗
///
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 queueList =new Queue();
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().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 artList=new List();
public static void getModelList()
{
// return;
NetWorkHeaders.GetUrlmodel((JsonData data1) =>
{
//ResourcesManager.ArtServerPath = data1["data"]["url"].ToString();
artList = new List();
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;
}
}
}
}
}