UserSceneManager.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. using LitJson;
  2. using Newtonsoft.Json;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using XRTool.Util;
  7. public class UserSceneManager : XRTool.Util.Singleton<UserSceneManager>
  8. {
  9. public delegate void UserSceneInitEnd(bool b);
  10. //下载回调
  11. public UserSceneInitEnd callback;
  12. int max;
  13. int now;
  14. //场景中的模型
  15. public Dictionary<string, UserSceneItem> SceneList = new Dictionary<string, UserSceneItem>();
  16. //初始化场景
  17. public IEnumerator initScene(string msg)
  18. {
  19. UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.sninfo);
  20. SceneList.Clear();
  21. JsonData data = JsonMapper.ToObject(msg);
  22. Debug.Log("initScene init"+ msg);
  23. if (data["data"]["list"].IsArray)
  24. {
  25. max = data["data"]["list"].Count;
  26. Debug.Log("initScene IsArray");
  27. for (int i = 0; i < data["data"]["list"].Count; i++)
  28. {
  29. yield return GameManager.Instance.StartCoroutine( init(data["data"]["list"][i]["id"].ToString(), data["data"]["list"][i]["name"].ToString()));
  30. }
  31. }
  32. else
  33. {
  34. callback?.Invoke(true);
  35. }
  36. }
  37. public IEnumerator init(string id, string name)
  38. {
  39. SendSnInfo sendNet = new SendSnInfo();
  40. sendNet.sn = SendSN.GetSN();
  41. sendNet.projectId = int.Parse(id);
  42. string jsonData = JsonMapper.ToJson(sendNet);
  43. SendInit detail = new SendInit();
  44. yield return GameScene.Instance.StartCoroutine(HttpTool.Instance.SendHttp(HttpAction.client_snInfo, jsonData, (message) =>
  45. {
  46. Debug.Log(" 初始化场景 client_snInfo==》" + message);
  47. detail.projectId = int.Parse(id);
  48. detail.sn = SendSN.GetSN();
  49. }));
  50. yield return null;
  51. string str = JsonConvert.SerializeObject(detail);
  52. UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), " 正在初始化场景");
  53. yield return GameScene.Instance.StartCoroutine(HttpTool.Instance.SendHttp(HttpAction.sn_init, str, (mes) =>
  54. {
  55. Debug.Log(" 初始化场景 sn_init==》" + mes + "===>id" + detail.projectId.ToString());
  56. JsonData data = JsonMapper.ToObject(mes);
  57. if (data["data"].ToString() != null)
  58. {
  59. CreateItem(data["data"]["info"], detail.projectId.ToString());
  60. }else
  61. {
  62. UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), HttpAction.sn_init+" 网络通讯异常 请重启应用");
  63. }
  64. }));
  65. }
  66. Dictionary<string,JsonData> msglist = new Dictionary<string,JsonData>();
  67. public static JsonData smsg;
  68. void CreateItem(JsonData msg,string id)
  69. {
  70. msglist.Add(id,msg);
  71. // JsonConvert.DeserializeObject<UserSceneItem>(msg.ToJson());
  72. UserSceneItem usi = new UserSceneItem();//
  73. usi.id = id;
  74. usi.name = msg["name"].ToString();
  75. if(msg["sentiment"]!=null)
  76. usi.sentiment = msg["sentiment"].ToString();
  77. if (msg["updateTime"] != null)
  78. usi.updateTime = msg["updateTime"].ToString();
  79. if (msg["navLines"] != null)
  80. usi.navLines = msg["navLines"].ToString();
  81. if (msg["status"] != null)
  82. usi.status = msg["status"].ToString();
  83. if (msg["describe"] != null)
  84. usi.describe = msg["describe"].ToString();
  85. if (msg["image"] != null)
  86. usi.image = msg["image"].ToString();
  87. if (msg["map"] != null)
  88. usi.map = msg["map"].ToString();
  89. if (msg["sandTable"] != null)
  90. usi.sandTable = msg["sandTable"].ToString();
  91. GameManager.Instance.m_scene = usi;
  92. if (msg["listSpoit"] != null)
  93. {
  94. if(msg["listSpoit"].IsArray)
  95. {
  96. for (int i = 0; i < msg["listSpoit"].Count; i++)
  97. {
  98. SpotsItem si = new SpotsItem();
  99. si.usi = usi;
  100. si.position = JsonConvert.DeserializeObject<List<sspos>>(msg["listSpoit"][i]["spoitTransform"].ToJson());
  101. si.id = msg["listSpoit"][i]["id"].ToString();
  102. si.name = msg["listSpoit"][i]["name"].ToString();
  103. si.triggerImageMark = msg["listSpoit"][i]["triggerImageMark"].ToString();
  104. if (msg["listSpoit"][i]["spoittf"]!=null)
  105. {
  106. si.initSpoitTfInfo(msg["listSpoit"][i]["spoittf"]);
  107. }
  108. else
  109. {
  110. si.SpotsObj.transform.localPosition = Vector3.zero;
  111. si.SpotsObj.transform.localEulerAngles = Vector3.zero;
  112. si.SpotsObj.transform.localScale = Vector3.one;
  113. }
  114. si.updateTime = msg["listSpoit"][i]["updateTime"].ToString();
  115. si.triggerImageId =int.Parse( msg["listSpoit"][i]["triggerImageId"].ToString());
  116. if ( msg["listSpoit"][i].Keys.Contains("triggerImage"))
  117. si.triggerImage = msg["listSpoit"][i]["triggerImage"].ToString();
  118. if(msg["listSpoit"][i]["material"]!=null&& msg["listSpoit"][i]["material"].IsArray)
  119. {
  120. for (int j = 0; j < msg["listSpoit"][i]["material"].Count; j++)
  121. {
  122. if(ModelManager.Instance.modellist.ContainsKey(int.Parse(msg["listSpoit"][i]["material"][j]["id"].ToString())))
  123. {
  124. ModelList modellist = ModelManager.Instance.GetModelList(int.Parse(msg["listSpoit"][i]["material"][j]["id"].ToString()));
  125. Debug.Log("DGJ ====> "+ msg["listSpoit"][i]["material"][j]["id"].ToString() + "_" +(msg["listSpoit"][i]["material"][j]["objectTransform"].ToJson()));
  126. modellist.objectTransform = JsonConvert.DeserializeObject<ObjectTransform>(msg["listSpoit"][i]["material"][j]["objectTransform"].ToJson());
  127. // modellist._model.transform.parent = si.SpotsObj.transform;
  128. modellist.spotsItem = si;
  129. modellist.select = bool.Parse(msg["listSpoit"][i]["material"][j]["select"].ToString());
  130. modellist.init(false);
  131. for (int l = 0; l < modellist.materialList.Count; l++)
  132. {
  133. Debug.Log("DGJ New ====> " + modellist.materialList[l].name);
  134. modellist.materialList[l].modelList = modellist.Model;
  135. }
  136. si.modelList.Add(msg["listSpoit"][i]["material"][j]["id"].ToString(), modellist);
  137. if (msg["listSpoit"][i]["material"][j]["materialList"]!=null&& msg["listSpoit"][i]["material"][j]["materialList"].IsArray)
  138. {
  139. for (int z = 0; z < msg["listSpoit"][i]["material"][j]["materialList"].Count; z++)
  140. {
  141. Debug.Log("DGJ2 ====> "+ si.triggerImage + "_" + msg["listSpoit"][i]["material"][j]["materialList"][z]["id"].ToJson() + "_" + (msg["listSpoit"][i]["material"][j]["materialList"][z]["objectTransform"].ToJson()));
  142. modellist.materialList[z].objectTransform = JsonConvert.DeserializeObject<ObjectTransform>(msg["listSpoit"][i]["material"][j]["materialList"][z]["objectTransform"].ToJson());
  143. //modellist.materialList[z].initModelObj();
  144. Debug.Log("DGJ2 ====> " + indexa+"_" + modellist.materialList[z].id+"_"+ msg["listSpoit"][i]["material"][j]["materialList"][z]["id"].ToJson());
  145. modellist.materialList[z].name = si.triggerImage;
  146. indexa++;
  147. // GameManager.Instance.StartCoroutine(modellist.materialList[z].initFrist());
  148. }
  149. }
  150. si.init();
  151. }
  152. else
  153. {
  154. Debug.Log("沒有找到===》" + int.Parse(msg["listSpoit"][i]["material"][j]["id"].ToString()));
  155. Debug.Log("沒有找到===》" + (msg["listSpoit"][i]["material"][j]["objectTransform"].ToJson()));
  156. }
  157. }
  158. }
  159. usi.SpotsList.Add(si.id,si);
  160. Debug.Log("UI Data 添加d景点===>" + si.name+"_"+ si.triggerImageMark);
  161. }
  162. }
  163. }
  164. usi.vufroiaTrigger = new VufroiaTrigger();
  165. // usi.vufroiaTrigger.init(msg);
  166. usi.vufroiaTrigger.msg = msg;
  167. usi.vufroiaTrigger.usi = usi;
  168. SceneList.Add(usi.id, usi);
  169. foreach (var usi2 in UserSceneManager.Instance.SceneList.Values)
  170. {
  171. foreach (var si in usi2.SpotsList.Values)
  172. {
  173. foreach (var item in si.modelList.Keys)
  174. {
  175. for (int ij = 0; ij < si.modelList[item].materialList.Count; ij++)
  176. {
  177. Debug.Log("測試====》" + si.modelList[item].materialList[ij].name+"_" + si.triggerImageMark);
  178. }
  179. }
  180. }
  181. }
  182. Debug.Log("UI Data 添加场景===>"+ usi.id);
  183. now++;
  184. if(max<=now)
  185. {
  186. callback?.Invoke(true);
  187. }
  188. }
  189. public static int indexa=0;
  190. public string nowId;
  191. public void gotoScene(string id)
  192. {
  193. nowId = id;
  194. if (SceneList.ContainsKey(id))
  195. SceneList[id].load();
  196. DataManager.Instance.ProjectID = int.Parse(id);
  197. JsonData msg = UserSceneManager.smsg;
  198. smsg = msglist[id];
  199. GameScene.Instance.o20.SetActive(true);
  200. }
  201. public Dictionary<string, UserSceneItem> GetScenes()
  202. {
  203. return SceneList;
  204. }
  205. }