123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542 |
- using LitJson;
- using OpenCVForUnity.CoreModule;
- using OpenCVForUnity.UnityUtils;
- using SC.XR.Unity.Module_InputSystem;
- using SC.XR.Unity.Module_InputSystem.InputDeviceGC.KS;
- using SC.XR.Unity.Module_InputSystem.InputDeviceHead;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Reflection;
- using UnityEngine;
- using static WindowConfig;
- public class WindowsManager : MonoSingleton<WindowsManager>
- {
- public bool isTest = true;
- public delegate void OnTipBackEvent(string msg);
- public OnTipBackEvent OnTipBackChange;
- public bool isShowTip;
- public WindowItemConfig wConfig;
- [HideInInspector]
- public Canvas canvasRoot;
- public List<windowItemGameObject> windowItemGameObjectList;
- public WindowConfig windowsConfig;
- public void DestroyText2D(Texture2D t2)
- {
- Destroy(t2);
- }
- InputDeviceHeadPart headPart;
- InputDeviceKSPart LeftPart;
- InputDeviceKSPart RightPart;
- private void Awake()
- {
- PlayerPrefs.DeleteAll();
- StartCoroutine(CheckIsStart());
-
- if (API_GSXR_Module_InputSystem_Head.GSXR_Head != null)
- {
- headPart = API_GSXR_Module_InputSystem_Head.GSXR_Head;
-
- }
- if (API_GSXR_Module_InputSystem_KS.GSXR_KSRight != null)
- {
- RightPart = API_GSXR_Module_InputSystem_KS.GSXR_KSRight;
- }
- if (API_GSXR_Module_InputSystem_KS.GSXR_KSLeft != null)
- {
- LeftPart = API_GSXR_Module_InputSystem_KS.GSXR_KSLeft;
- }
- }
- void initShowWindow()
- {
- for (int i = 0; i < windowItemGameObjectList.Count; i++)
- {
- if(windowItemGameObjectList[i].type == windowsConfig.initShowWindow)
- {
- windowItemGameObjectList[i].window.SetActive(true);
- }
- else
- {
- windowItemGameObjectList[i].window.SetActive(false);
- }
- }
- }
- public bool isStart = false;
- IEnumerator CheckIsStart()
- {
-
- try
- {
- Texture2D texture2D = Resources.Load("touxiang") as Texture2D;
- Mat imgMat = new Mat(texture2D.height, texture2D.width, CvType.CV_8UC4);
- Utils.texture2DToMat(texture2D, imgMat);
-
- imgMat.release();
- }
- catch { }
- while (HttpSDKAction.Instance.jsonData == "")
- {
- yield return null;
- }
-
- isStart = true;
- canvasRoot = GameObject.Instantiate(windowsConfig.canvas,this.transform);
- for (int i = 0; i < windowsConfig.initComponent.Count; i++)
- {
- canvasRoot.gameObject.AddComponent(GetTypeByName(windowsConfig.initComponent[i].name));
- }
- windowItemGameObjectList = new List<windowItemGameObject>();
- initWindowList(windowsConfig.windowItemGameObjectList, windowItemGameObjectList, canvasRoot.transform);
- initShowWindow();
- Application.targetFrameRate = 300;
- GameObject jt = GameObject.Instantiate( GetPrefab(windowType.XunJian, "JianTou"),OpenXRCamera.Instance.head.transform);
- jt.transform.localPosition = Vector3.forward;
- jt.transform.localEulerAngles = Vector3.zero;
- GameObject obj= GameObject.Instantiate(GetPrefab(windowType.XunJian, "SaoMiao"), OpenXRCamera.Instance.head.transform);
- obj.transform.localPosition = new Vector3(0,0,2f);
- obj.transform.localEulerAngles = Vector3.zero;
- GameObject.Instantiate(GetPrefab(windowType.XunJian, "ARSaoTu"));
- GameObject.Instantiate(GetPrefab(windowType.ProjectMain, "PlayerToImage"));
- GameObject.Instantiate(GetPrefab(windowType.RTC, "GHZRtcNew"));
- GameObject.Instantiate(GetPrefab(windowType.RTC, "Tools"));
- GameObject.Instantiate(GetPrefab(windowType.XunJian, "ImmersalSDK"));
- DianYunManager.Instance.stopSaoMiao();
- tipInfoGameObject = GameObject.Instantiate(GetPrefab(windowType.ProjectMain, "TipInfo"));
- }
- public GameObject tipInfoGameObject;
- public static System.Type GetTypeByName(string name)
- {
- foreach (Assembly assembly in System.AppDomain.CurrentDomain.GetAssemblies())
- {
- foreach (System.Type type in assembly.GetTypes())
- {
- if (type.Name == name)
- return type;
- }
- }
- return null;
- }
- void initWindowList(List<windowItemGameObject> list, List<windowItemGameObject> nowlist,Transform parent)
- {
- if(list!=null)
- {
- for (int i = 0; i < list.Count; i++)
- {
- windowItemGameObject wg = new windowItemGameObject();
- wg.type = list[i].type;
- wg.parentType = list[i].parentType;
- wg.window = GameObject.Instantiate(list[i].window, parent);
- wg.window.name = list[i].window.name;
- wg.windowItemGameObjectList = new List<windowItemGameObject>();
- initGameObject(wg.window);
- initWindowList(list[i].windowItemGameObjectList, wg.windowItemGameObjectList, wg.window.transform);
- nowlist.Add(wg);
- }
- }
- }
- void initGameObject(GameObject go)
- {
- go.transform.localPosition = Vector3.zero;
- go.transform.localEulerAngles = Vector3.zero;
- go.transform.localScale = Vector3.one;
- }
- public GameObject GetPrefab(windowType wt,string name)
- {
- for (int i = 0; i < wConfig.list.Count; i++)
- {
- if(wConfig.list[i].type==wt)
- {
- for (int j = 0; j < wConfig.list[i].PrefabList.Count; j++)
- {
- if(wConfig.list[i].PrefabList[j].name==name)
- {
- return wConfig.list[i].PrefabList[j].obj;
- }
- }
- }
- }
- return null;
- }
- Queue<TipData> tdlist = new Queue<TipData>();
- void setWindowData(windowType wt,GameObject go, string data)
- {
- TipData td = new TipData();
- td.data = data;
- td.go = go;
- td.wt = wt;
- tdlist.Enqueue(td);
-
- }
- bool isChangzhu(windowType wt)
- {
- switch (wt)
- {
- case windowType.Top:
- return true;
- }
- return false;
- }
- public float preJDInt;
- bool isHuLue(windowType wt)
- {
- switch (wt)
- {
- case windowType.Tip:
- return true;
- case windowType.Tip2:
- return true;
- case windowType.Error:
- return true;
- }
- return false;
- }
- Stack<windowType> wlist = new Stack<windowType>();
- public void show(windowType wt,bool needHandle = true,string data="")
- {
- List<windowItemGameObject> wglist = getWindow(wt, needHandle);
- for (int i = 0; i < wglist.Count; i++)
- {
- bool isTip = isHuLue(wglist[i].type);
- Debug.Log("isTip===>"+ isTip);
- setWindowData(wglist[i].type, wglist[i].window, data);
- if(!isTip)
- showManagerWindow(windowItemGameObjectList, wglist, wglist[i].type, needHandle);
- }
- switch(wt)
- {
- case windowType.XunJianStart:
- closeWindow(windowItemGameObjectList,windowType.Top);
- break;
- case windowType.XunJianLB:
- showWindow(windowItemGameObjectList, windowType.Top);
- break;
- }
- if(wlist.Count>0)
- {
- if(wlist.Peek()!=wt&& !wlist.Contains(wt))
- {
- wlist.Push(wt);
- }
- }else
- {
- wlist.Push(wt);
- }
- }
- windowItemGameObject showitem(List<windowItemGameObject> list,windowType wt, bool needHandle = true)
- {
- for (int i = 0; i < list.Count; i++)
- {
- windowItemGameObject wg = showitem(list[i].windowItemGameObjectList, wt);
- if(wg!=null)
- {
- return wg;
- }
- if (list[i].type == wt)
- {
- return list[i];
- }
- }
- return null;
- }
- List<windowItemGameObject> getWindow(windowType wt, bool needHandle = true)
- {
- List<windowItemGameObject> wiList = new List<windowItemGameObject>();
- int ct = 0;
- while (true)
- {
- windowItemGameObject wg = checkWindow(wt, needHandle);
- if (wg==null)
- {
- return wiList;
- }else
- {
- wt = wg.parentType;
- wiList.Add(wg);
- }
- ct++;
- if(ct>10000)
- {
- Debug.LogError("窗口获取失败");
- return new List<windowItemGameObject>();
- }
- }
- }
- windowItemGameObject checkWindow( windowType wt, bool needHandle = true)
- {
-
- for (int i = 0; i < windowItemGameObjectList.Count; i++)
- {
- if (windowItemGameObjectList[i].type == wt)
- {
- return windowItemGameObjectList[i];
- }
- windowItemGameObject wg = showitem(windowItemGameObjectList[i].windowItemGameObjectList, wt, needHandle);
- if (wg!=null)
- {
- return wg;
- }
- }
- return null;
- }
- void showWindow(List<windowItemGameObject> list, windowType wt)
- {
-
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i].type == wt)
- {
- list[i].window.SetActive(true);
- }
- showWindow(list[i].windowItemGameObjectList, wt);
- }
- }
- void closeWindow(List<windowItemGameObject> list, windowType wt)
- {
-
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i].type == wt)
- {
- list[i].window.SetActive(false);
- }
- closeWindow(list[i].windowItemGameObjectList, wt);
- }
- }
- void showManagerWindow(List<windowItemGameObject> list, List<windowItemGameObject> wglist, windowType wt, bool needHandle = true)
- {
-
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i].type == wt)
- {
- list[i].window.SetActive(true) ;
- }
- else
- {
- if(!isChangzhu(list[i].type)&& needHandle&& !isHuLue(list[i].type))
- {
- bool isShow=false;
- for (int j = 0; j < wglist.Count; j++)
- {
- if(wglist[j].type== list[i].type)
- {
- isShow = true;
- }
- }
- if(!isShow)
- {
- list[i].window.SetActive(false);
- }
- }
- }
- showManagerWindow(list[i].windowItemGameObjectList, wglist, wt, needHandle);
- }
- }
- void updatePart()
- {
- }
- private void Update()
- {
-
- if (tdlist.Count>0&&!isShowTip)
- {
- TipData td = tdlist.Dequeue();
- Debug.Log("准备显示Tip");
- switch (td.wt)
- {
- case windowType.Tip2:
- preJDInt = 30;
- Tip2Window t2w = td.go.GetComponent<Tip2Window>();
- td.go.SetActive(true);
- isShowTip = true;
- t2w.showTxt(td.data, () => {
- OnTipBackChange?.Invoke("");
- });
- break;
- case windowType.Tip:
- preJDInt = 30;
- Tip1Window tw = td.go.GetComponent<Tip1Window>();
- td.go.SetActive(true);
- isShowTip = true;
- JsonData d = JsonMapper.ToObject(td.data);
- Color c = new Color(float.Parse(d["cr"].ToString()), float.Parse(d["cg"].ToString()), float.Parse(d["cb"].ToString()), float.Parse(d["ca"].ToString()));
- List<string> blist = new List<string>();
- blist.Add(d["blist"][0].ToString());
- blist.Add(d["blist"][1].ToString());
- blist.Add(d["blist"][2].ToString());
- tw.show(d["title"].ToString(), d["info"].ToString(),bool.Parse( d["isQianWang"].ToString()), bool.Parse(d["isSuccess"].ToString()), getTexture(d["Texture"].ToString()), c, blist, (string msg)=> {
- OnTipBackChange?.Invoke(msg);
- });
- break;
- case windowType.Error:
- preJDInt = 30;
- if (WindowGenSui.Instance.jd >= 30)
- preJDInt = WindowGenSui.Instance.jd;
- WindowGenSui.Instance.jd = 10;
- saveNowWindowAndClose(false);
- ErrorManager em = td.go.GetComponent<ErrorManager>();
- td.go.SetActive(true);
- isShowTip = true;
- JsonData de = JsonMapper.ToObject(td.data);
- Color ce = new Color(float.Parse(de["cr"].ToString()), float.Parse(de["cg"].ToString()), float.Parse(de["cb"].ToString()), float.Parse(de["ca"].ToString()));
- List<string> bliste = new List<string>();
- bliste.Add(de["blist"][0].ToString());
- bliste.Add(de["blist"][1].ToString());
- bliste.Add(de["blist"][2].ToString());
- em.show(de["title"].ToString(), de["info"].ToString(), ce, getTexture(de["Texture"].ToString()), bliste, (string msg) => {
- saveNowWindowAndClose(true);
- OnTipBackChange?.Invoke(msg);
- },bool.Parse(de["isText"].ToString()), de["djsMsg"].ToString(),int.Parse(de["time"].ToString()), de["bt0name"].ToString(), de["bt1name"].ToString(), de["bt2name"].ToString());
-
- break;
- }
- }
- }
- List<windowItemGameObject> showList;
- void saveNowWindowAndClose(bool isRef)
- {
- if(!isRef)
- {
- showList = new List<windowItemGameObject>();
- for (int i = 0; i < windowItemGameObjectList.Count; i++)
- {
- if (windowItemGameObjectList[i].window.activeSelf&& windowItemGameObjectList[i].type!= windowType.Error)
- {
- showList.Add(windowItemGameObjectList[i]);
- windowItemGameObjectList[i].window.SetActive(false);
- }
- }
- }else
- {
- for (int i = 0; i < showList.Count; i++)
- {
- showList[i].window.SetActive(true);
- }
- }
- }
- public Texture getTexture(string texId)
- {
- for (int i = 0; i < wConfig.listTexture.Count; i++)
- {
- if(wConfig.listTexture[i].PrefabList.name== texId)
- {
- return wConfig.listTexture[i].PrefabList.obj;
- }
- }
- return null;
- }
- public JsonData getErrorData(string title, string info, Color color, string icon, List<string> backList, bool isText = true, string djsMsg = "", int time = 5, string bt0 = "", string bt1 = "", string bt2 = "")
- {
- JsonData data = new JsonData();
- data["title"] = title;
- data["info"] = info;
- data["isText"] = isText;
- data["djsMsg"] = djsMsg;
- data["time"] = time;
- data["Texture"] = icon;
- data["bt0name"] = bt0;
- data["bt1name"] = bt1;
- data["bt2name"] = bt2;
- data["blist"] = new JsonData();
- for (int i = 0; i < 3; i++)
- {
- data["blist"].Add(backList[i]);
- }
- data["cr"] = color.r;
- data["cg"] = color.g;
- data["cb"] = color.b;
- data["ca"] = color.a;
- return data;
- }
- public JsonData getTip1Data(string title, string info, bool isQianWang, bool isSuccess, string texID, Color color, List<string> backList)
- {
- JsonData data = new JsonData();
- data["title"] = title;
- data["info"] = info;
- data["isQianWang"] = isQianWang;
- data["isSuccess"] = isSuccess;
- data["Texture"] = texID;
- data["blist"] = new JsonData();
- for (int i = 0; i < 3; i++)
- {
- data["blist"].Add(backList[i]);
- }
- data["cr"] = color.r;
- data["cg"] = color.g;
- data["cb"] = color.b;
- data["ca"] = color.a;
- return data;
- }
- void testTip()
- {
- WindowsManager.Instance.show(WindowConfig.windowType.Tip2, false, "敬请期待!");
- List<string> backTip = new List<string>();
- backTip.Add("test1");
- backTip.Add("test2");
- backTip.Add("test3");
- WindowsManager.Instance.show(WindowConfig.windowType.Error, false, WindowsManager.Instance.getErrorData("提示", "敬请期待!", Color.gray, "icon", backTip, true, "敬请期待", 5).ToJson());
- WindowsManager.Instance.show(WindowConfig.windowType.Error, false, WindowsManager.Instance.getErrorData("提示", "敬请期待!", Color.gray, "icon", backTip, false, "敬请期待", 5).ToJson());
- }
- public class TipData
- {
- public windowType wt;
- public GameObject go;
- public string data;
- }
- }
|