MachineRoomManager.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. using System.Linq;
  2. using Newtonsoft.Json;
  3. using SC.XR.Unity.Module_InputSystem;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using UnityEngine;
  9. using UnityEngine.UI;
  10. using UnityEngine.XR;
  11. using Ximmerse.XR.Tag;
  12. using Newtonsoft.Json.Linq;
  13. /// <summary>
  14. /// 大场景生成和Tag管理
  15. /// </summary>
  16. public class MachineRoomManager : MonoSingleton<MachineRoomManager>
  17. {
  18. public MachineRoomData data;
  19. public GameObject cabinetObj;
  20. public GameObject bladeServer;
  21. public bool isInit = false;
  22. public MachineRoomTagData tagData;
  23. public List<EditorTag> listEditorTag;
  24. GameObject tagObjPoint;
  25. private List<BladeServerItem> listBSItem;
  26. public TagTracking foundTracking;
  27. public GameObject cubeY;
  28. public Transform leftLine;
  29. public Transform rightLine;
  30. bool isSelect = false;
  31. private Transform selectTrigger;
  32. private Vector3 selectTOldPos;
  33. private Vector3 selectTOldRot;
  34. public bool isDataInit = false;
  35. public Transform startShowDevice;
  36. /// <summary>
  37. /// 临时创建 的tagid
  38. /// </summary>
  39. private List<int> listTagid;
  40. /// <summary>
  41. /// 临时创建 刀片机信息
  42. /// </summary>
  43. private DeviceParameters dp1;
  44. private DeviceParameters dp2;
  45. /// <summary>
  46. /// 机房列表
  47. /// </summary>
  48. public List<string> listRoomName;
  49. public void Init()
  50. {
  51. tagObjPoint = new GameObject();
  52. listBSItem = new List<BladeServerItem>();
  53. listRoomName = new List<string>();
  54. listRoomName.Add("4A-23");
  55. listRoomName.Add("4A-24");
  56. listRoomName.Add("4A-25");
  57. listRoomName.Add("4A-26");
  58. listRoomName.Add("4A-27");
  59. listTagid = new List<int>();
  60. listTagid.Add(6);
  61. listTagid.Add(15);
  62. listTagid.Add(26);
  63. listTagid.Add(27);
  64. listTagid.Add(28);
  65. listTagid.Add(30);
  66. listTagid.Add(31);
  67. listTagid.Add(32);
  68. listTagid.Add(35);
  69. listTagid.Add(36);
  70. listTagid.Add(38);
  71. listTagid.Add(41);
  72. //listTagid.Add(42);
  73. //listTagid.Add(43);
  74. //listTagid.Add(44);
  75. //listTagid.Add(50);
  76. //listTagid.Add(53);
  77. //listTagid.Add(55);
  78. //listTagid.Add(58);
  79. //listTagid.Add(61);
  80. //listTagid.Add(62);
  81. //listTagid.Add(64);
  82. //listTagid.Add(31);
  83. //listTagid.Add(61);
  84. //listTagid.Add(64);
  85. //listTagid.Add(43);
  86. //listTagid.Add(3161);
  87. //listTagid.Add(3164);
  88. //listTagid.Add(4361);
  89. //listTagid.Add(4364);
  90. #region 原初始化
  91. // //PlayerPrefs.DeleteAll();
  92. // if (PlayerPrefs.HasKey("MachineRoomData"))
  93. // {
  94. // string msg = PlayerPrefs.GetString("MachineRoomData");
  95. // UILogManager.Instance.text1.text = msg;
  96. // Debug.Log("MachineRoomData " + msg);
  97. // data = JsonConvert.DeserializeObject<MachineRoomData>(msg);
  98. // // Debug.Log("PlayerPrefs.HasKey(MachineRoomData) ");
  99. // //data = new MachineRoomData();
  100. // //data.line = 4;
  101. // //data.list = 3;
  102. // //data.intervalW = 1;
  103. // //data.intervalL = 2;
  104. // //data.cabinetW = 1.2f;
  105. // //data.cabinetH = 2f;
  106. // //data.bladeSeverNumber = 4;
  107. // //data.bIntervalH = 0.2f;
  108. // //data.firstBladeSeverH = 0.4f;
  109. // //data.TagOffestPosY = 0;
  110. // //data.CameraFar = 3;
  111. // //data.roomName = "4A-23";
  112. // //data.totalCapacity = 8520;
  113. // //data.usedCapacity = 4420;
  114. // //data.totalPower = 1278;
  115. // //data.usedPower = 846.24f;
  116. // //data.totalLoadBearing = 85.2f;
  117. // //data.usedBearing = 46.83f;
  118. // }
  119. // else
  120. // {
  121. // data = new MachineRoomData();
  122. // data.line = 4;
  123. // data.list = 3;
  124. // data.intervalW = 0.1f;
  125. // data.intervalL = 1f;
  126. // data.cabinetW = 0.6f;
  127. // data.cabinetH = 2f;
  128. // data.bladeSeverNumber = 4;
  129. // data.bIntervalH = 0.2f;
  130. // data.firstBladeSeverH = 0.4f;
  131. // data.tagOffestPosY = 1f;
  132. // data.cameraFar = 10;
  133. // data.roomName = "4A-23";
  134. // data.totalCapacity = 8520;
  135. // data.usedCapacity = 4420;
  136. // data.totalPower = 1278;
  137. // data.usedPower = 846.24f;
  138. // data.totalLoadBearing = 85.2f;
  139. // data.usedBearing = 46.83f;
  140. // }
  141. // // data.listCabinetData = null;
  142. // data.listEquipmentData = null;
  143. // data.listTagData = null;
  144. //// PlayerPrefs.DeleteAll();
  145. // if (PlayerPrefs.HasKey("MachineRoomTagData"))
  146. // {
  147. // string msg = PlayerPrefs.GetString("MachineRoomTagData");
  148. // Debug.Log("MachineRoomTagData " + msg);
  149. // data.listTagData = JsonConvert.DeserializeObject<List<MachineRoomTagData>>(msg);
  150. // }
  151. // else
  152. // {
  153. // data.listTagData = new List<MachineRoomTagData>();
  154. // MachineRoomTagData data1 = new MachineRoomTagData();
  155. // data1.id = 65;
  156. // //data1.pos = new Vector3(4.5f, 0, 0);
  157. // data1.pos = Vector3.zero;
  158. // data1.rot = new Vector3(0, 180, 0);
  159. // data1.offestPos = Vector3.zero;
  160. // data1.offestrot = Vector3.zero;
  161. // MachineRoomTagData data4 = new MachineRoomTagData();
  162. // data4.id = 141;
  163. // // data4.pos = new Vector3(4.5f, 2.5f, 3.7f);
  164. // data4.pos = Vector3.zero;
  165. // data4.rot = new Vector3(0, 180, 0);
  166. // data4.offestPos = Vector3.zero;
  167. // data4.offestrot = Vector3.zero;
  168. // MachineRoomTagData data5 = new MachineRoomTagData();
  169. // data5.id = 142;
  170. // // data5.pos = new Vector3(4.5f, 2.5f, 3.7f);
  171. // data5.pos = Vector3.zero;
  172. // data5.rot = new Vector3(0, 180, 0);
  173. // data5.offestPos = Vector3.zero;
  174. // data5.offestrot = Vector3.zero;
  175. // data.listTagData.Add(data1);
  176. // data.listTagData.Add(data4);
  177. // data.listTagData.Add(data5);
  178. // }
  179. // if (PlayerPrefs.HasKey("MachineRoomCabinetData"))
  180. // {
  181. // string msg = PlayerPrefs.GetString("MachineRoomCabinetData");
  182. // // data.listCabinetData = JsonConvert.DeserializeObject<List<MachineRoomCabinetData>>(msg);
  183. // data.listEquipmentData = JsonConvert.DeserializeObject<List<MachineParameters>>(msg);
  184. // }
  185. #endregion
  186. }
  187. private void Start()
  188. {
  189. Init();
  190. //Init();
  191. // Init();
  192. #if UNITY_EDITOR
  193. // Init();
  194. #endif
  195. }
  196. public void SceneInitCallBack(string msg)
  197. {
  198. Debug.Log(msg);
  199. JObject json = JObject.Parse(msg);
  200. UILogManager.Instance.text1.text = msg;
  201. if (json["code"].ToString() == "200")
  202. {
  203. string data = json["data"]["room"].ToString();
  204. this.data = JsonConvert.DeserializeObject<MachineRoomData>(data);
  205. UICallManager.Instance.MachineRoomInit();
  206. }
  207. else
  208. {
  209. Debug.LogError(" 请求场景参数出错 !!! " + HttpActionLang.sceneInit);
  210. }
  211. }
  212. public void SceneInit()
  213. {
  214. SettingMachineRoomData.Instance.Init(data);
  215. OpenXRCamera.Instance.head.GetComponent<Camera>().farClipPlane = data.cameraFar;
  216. MachineInit();
  217. // ServerInit();
  218. UICallManager.Instance.ShowDeviceTransform(startShowDevice);
  219. isDataInit = true;
  220. }
  221. private void Update()
  222. {
  223. if (state && tagData != null)
  224. {
  225. for (int i = 0; i < listEditorTag.Count; i++)
  226. {
  227. listEditorTag[i].gameObject.SetActive(!state);
  228. if (listEditorTag[i].id == tagData.id)
  229. listEditorTag[i].gameObject.SetActive(true);
  230. }
  231. }
  232. if (tagData != null && foundTracking != null && DragManager.Instance.triggerState == TriggerState.No && !state)
  233. {
  234. tagObjPoint.transform.SetParent(foundTracking.transform);
  235. tagObjPoint.transform.localEulerAngles = new Vector3(0, tagData.offestrot == Vector3.zero ? tagData.rot.y : tagData.offestrot.y, 0);
  236. tagObjPoint.transform.localPosition = tagData.offestPos == Vector3.zero ? tagData.pos : tagData.offestPos;
  237. // Debug.Log(" MachineRoom T " + tagData.offestPos);
  238. transform.eulerAngles = new Vector3(0, tagObjPoint.transform.eulerAngles.y, 0);
  239. transform.position = new Vector3(tagObjPoint.transform.position.x, foundTracking.transform.position.y + data.tagOffestPosY, tagObjPoint.transform.position.z);
  240. }
  241. if (Input.GetKeyDown(KeyCode.L))
  242. {
  243. OnTrackingFound(foundTracking);
  244. }
  245. }
  246. public List<MachineObj> listObjes = new List<MachineObj>();
  247. public void MachineInit()
  248. {
  249. //listObjes.Clear();
  250. //listObjes = new List<MachineObj>();
  251. //// 重新生成机柜组
  252. //if(data.listEquipmentData == null||data.listEquipmentData.Count!=(data.line*data.list))
  253. //{
  254. // data.listEquipmentData = new List<MachineParameters>();
  255. // for (int i = 0; i < data.line; i++)
  256. // {
  257. // for (int j = 0; j < data.list; j++)
  258. // {
  259. // MachineParameters mp1 = new MachineParameters();
  260. // mp1.deviceId = (i * data.list + j + 1).ToString();
  261. // mp1.tagID = -1000;
  262. // // mp1.offsetPos = new Vector3(-0.4f, 0, -0.3f);
  263. // mp1.offsetPos = Vector3.zero;
  264. // mp1.eulerAxle = 3;
  265. // mp1.deviceName = "设备" + (i * data.list + j + 1).ToString();
  266. // mp1.carryingSystem = "承载系统1";
  267. // mp1.deviceLocation = "4A-23机房";
  268. // mp1.equipmentType = "机柜";
  269. // mp1.equipmentModel = null;
  270. // mp1.factory = null;
  271. // mp1.specification = null;
  272. // mp1.listDevicesParameters = new List<DeviceParameters>();
  273. // if (int.Parse( mp1.deviceId) % 2 == 0)
  274. // mp1.listDevicesParameters.Add(dp1);
  275. // else
  276. // mp1.listDevicesParameters.Add(dp2);
  277. // data.listEquipmentData.Add(mp1);
  278. // }
  279. // }
  280. // for (int i = 0; i < listTagid.Count; i++)
  281. // {
  282. // if ((i + 1) < data.listEquipmentData.Count)
  283. // {
  284. // data.listEquipmentData[i].tagID = listTagid[i];
  285. // }
  286. // else
  287. // break;
  288. // }
  289. //}
  290. GameObject rDataItem = Resources.Load<GameObject>("DataItem");
  291. for (int i = 0; i < data.listEquipmentData.Count; i++)
  292. {
  293. GameObject obj = GameObject.Instantiate(cabinetObj, transform);
  294. obj.transform.localScale = new Vector3(data.cabinetW, data.cabinetH, obj.transform.localScale.z);
  295. Debug.Log(data.cabinetH + " " + data.cabinetW);
  296. obj.name =i.ToString();
  297. // Debug.Log(obj.name + " " + new Vector3(j * (data.cabinetW + data.intervalW), 0, i * data.intervalL));
  298. obj.transform.localPosition = new Vector3((i%data.list)*(data.cabinetW + data.intervalW), 0, (i/data.list) * data.intervalL);
  299. obj.GetComponent<MachineObj>().Setting((i / data.list) % 2 == 0);
  300. listObjes.Add(obj.GetComponent<MachineObj>());
  301. listObjes[i].deviceParameters = data.listEquipmentData[i];
  302. if(data.listEquipmentData[i]!=null)
  303. {
  304. GameObject item = GameObject.Instantiate(rDataItem);
  305. DataItem dataItem = item.GetComponent<DataItem>();
  306. dataItem.Init(data.listEquipmentData[i]);
  307. // item.SetActive(true);
  308. for (int j = 0; j < data.listEquipmentData[i].listDevicesParameters.Count; j++)
  309. {
  310. dataItem.SetDeviceParametersData(data.listEquipmentData[i].listDevicesParameters);
  311. }
  312. listObjes[i].dataItem = dataItem;
  313. dataItem.transform.SetParent(listObjes[i].transform);
  314. dataItem.transform.localPosition = listObjes[i].xTag.localPosition;
  315. dataItem.transform.localEulerAngles = new Vector3(0, listObjes[i].isSingle ? 180 : 0, 0);
  316. }
  317. }
  318. //Debug.Log(data.line);
  319. Vector3 leftPos = new Vector3(-1 * (data.cabinetW + data.intervalW), 0, 0);
  320. Vector3 rightPos = new Vector3((data.cabinetW * data.list + data.intervalW * data.list + data.cabinetW + data.intervalW), 0, 0);
  321. WayFindingManager.Instance.SetLine(leftPos, rightPos);
  322. SaveAllData();
  323. isInit = true;
  324. }
  325. public IEnumerator RandomRange()
  326. {
  327. yield return 2f;
  328. int randomNum = UnityEngine.Random.Range(0, listObjes.Count-1);
  329. // WayFindingManager.Instance.SetServerItem(listObjes[randomNum].transform);
  330. List<MachineObj> listMachineObj = new List<MachineObj>();
  331. for (int i = 0; i < 3; i++)
  332. {
  333. if(i<listObjes.Count-1)
  334. {
  335. listMachineObj.Add(listObjes[i]);
  336. }
  337. }
  338. WayFindingManager.Instance.NavigatorServer(listMachineObj);
  339. }
  340. public void ServerInit()
  341. {
  342. // if (data.listCabinetData == null)
  343. // return;
  344. //// GameObject rDataItem = Resources.Load<GameObject>("DataItem");
  345. // for (int i = 0; i < data.listCabinetData.Count; i++)
  346. // {
  347. // if (data.listCabinetData[i].listBladeServerData == null)
  348. // continue;
  349. // for (int j = 0; j < data.listCabinetData[i].listBladeServerData.Count; j++)
  350. // {
  351. // GameObject item = GameObject.Instantiate(rDataItem);
  352. // DataItem dataItem = item.GetComponent<DataItem>();
  353. // dataItem.Init(data.listCabinetData[i].listBladeServerData[j].tagID, data.listCabinetData[i].listBladeServerData[j].pos, data.listCabinetData[i].listBladeServerData[j].eulerAxle , data.listCabinetData[i].listBladeServerData[j], data.listCabinetData[i].listBladeServerData[j].width, data.listCabinetData[i].listBladeServerData[j].heigth);
  354. // }
  355. // }
  356. if (data.listEquipmentData == null)
  357. return;
  358. GameObject rDataItem = Resources.Load<GameObject>("DataItem");
  359. for (int i = 0; i < data.listEquipmentData.Count; i++)
  360. {
  361. GameObject item = GameObject.Instantiate(rDataItem);
  362. DataItem dataItem = item.GetComponent<DataItem>();
  363. dataItem.Init(data.listEquipmentData[i]);
  364. // item.SetActive(true);
  365. for (int j = 0; j < data.listEquipmentData[i].listDevicesParameters.Count;j++)
  366. {
  367. dataItem.SetDeviceParametersData(data.listEquipmentData[i].listDevicesParameters);
  368. }
  369. }
  370. }
  371. public void SettingMachine( )
  372. {
  373. if (listObjes != null)
  374. {
  375. for (int i = 0; i < listObjes.Count; i++)
  376. {
  377. listObjes[i].gameObject.SetActive(false);
  378. }
  379. listObjes.Clear();
  380. listObjes = new List<MachineObj>();
  381. }
  382. if(BladeServerManager.Instance.listTagTracking!=null)
  383. {
  384. for (int i = 0; i < BladeServerManager.Instance.listTagTracking.Count; i++)
  385. {
  386. BladeServerManager.Instance.listTagTracking[i].gameObject.SetActive(false);
  387. }
  388. BladeServerManager.Instance.listTagTracking.Clear();
  389. }
  390. //data.listEquipmentData = new List<MachineParameters>();
  391. //for (int i = 0; i < data.line; i++)
  392. //{
  393. // for (int j = 0; j < data.list; j++)
  394. // {
  395. // MachineParameters mp1 = new MachineParameters();
  396. // mp1.deviceId = (i * data.list + j + 1).ToString();
  397. // mp1.tagID = -1000;
  398. // mp1.offsetPos = new Vector3(0f, 0, 0f);
  399. // mp1.eulerAxle = 3;
  400. // mp1.deviceName = "设备" + (i * data.list + j + 1).ToString();
  401. // mp1.carryingSystem = "承载系统1";
  402. // mp1.deviceLocation = "4A-23机房";
  403. // mp1.equipmentType = "机柜";
  404. // mp1.equipmentModel = null;
  405. // mp1.factory = null;
  406. // mp1.specification = null;
  407. // mp1.listDevicesParameters = new List<DeviceParameters>();
  408. // if (int.Parse( mp1.deviceId) % 2 == 0)
  409. // mp1.listDevicesParameters.Add(dp1);
  410. // else
  411. // mp1.listDevicesParameters.Add(dp2);
  412. // data.listEquipmentData.Add(mp1);
  413. // }
  414. //}
  415. //Debug.Log(data.line);
  416. //for (int i = 0; i < listTagid.Count; i++)
  417. //{
  418. // if (data.listEquipmentData.Count < (i + 1))
  419. // {
  420. // Debug.Log("a "+listTagid);
  421. // Debug.Log(data.listEquipmentData[i].tagID);
  422. // data.listEquipmentData[i].tagID = listTagid[i];
  423. // }
  424. //}
  425. //for (int i = 0; i < data.listEquipmentData.Count; i++)
  426. //{
  427. // GameObject obj = GameObject.Instantiate(cabinetObj, transform);
  428. // obj.transform.localScale = new Vector3(data.cabinetW, data.cabinetH, obj.transform.localScale.z);
  429. // Debug.Log(data.cabinetH + " " + data.cabinetW);
  430. // obj.name = data.listEquipmentData[i].deviceName;
  431. // // Debug.Log(obj.name + " " + new Vector3(j * (data.cabinetW + data.intervalW), 0, i * data.intervalL));
  432. // obj.transform.localPosition = new Vector3((i % data.line) * (data.cabinetW + data.intervalW), 0, i * data.intervalL);
  433. // obj.GetComponent<MachineObj>().Setting((i % data.line) % 2 == 0);
  434. // listObjes.Add(obj.GetComponent<MachineObj>());
  435. // listObjes[i].deviceParameters = data.listEquipmentData[i];
  436. //}
  437. //Vector3 leftPos = new Vector3(-1 * (data.cabinetW + data.intervalW), 0, 0);
  438. //Vector3 rightPos = new Vector3((data.cabinetW * data.list + data.intervalW * data.list), 0, 0);
  439. //WayFindingManager.Instance.SetLine(leftPos, rightPos);
  440. GameObject rDataItem = Resources.Load<GameObject>("DataItem");
  441. for (int i = 0; i < data.listEquipmentData.Count; i++)
  442. {
  443. GameObject obj = GameObject.Instantiate(cabinetObj, transform);
  444. obj.transform.localScale = new Vector3(data.cabinetW, data.cabinetH, obj.transform.localScale.z);
  445. Debug.Log(data.cabinetH + " " + data.cabinetW);
  446. obj.name = data.listEquipmentData[i].deviceName;
  447. // Debug.Log(obj.name + " " + new Vector3(j * (data.cabinetW + data.intervalW), 0, i * data.intervalL));
  448. obj.transform.localPosition = new Vector3((i % data.line) * (data.cabinetW + data.intervalW), 0, (i / data.line) * data.intervalL);
  449. obj.GetComponent<MachineObj>().Setting((i / data.line) % 2 == 0);
  450. listObjes.Add(obj.GetComponent<MachineObj>());
  451. listObjes[i].deviceParameters = data.listEquipmentData[i];
  452. GameObject item = GameObject.Instantiate(rDataItem);
  453. DataItem dataItem = item.GetComponent<DataItem>();
  454. dataItem.Init(data.listEquipmentData[i]);
  455. // item.SetActive(true);
  456. for (int j = 0; j < data.listEquipmentData[i].listDevicesParameters.Count; j++)
  457. {
  458. dataItem.SetDeviceParametersData(data.listEquipmentData[i].listDevicesParameters);
  459. }
  460. listObjes[i].dataItem = dataItem;
  461. dataItem.transform.SetParent(listObjes[i].transform);
  462. dataItem.transform.localPosition = listObjes[i].xTag.localPosition;
  463. dataItem.transform.localEulerAngles = new Vector3(0, listObjes[i].isSingle ? 180 : 0, 0);
  464. }
  465. //Debug.Log(data.line);
  466. Vector3 leftPos = new Vector3(-1 * (data.cabinetW + data.intervalW), 0, 0);
  467. Vector3 rightPos = new Vector3((data.cabinetW * data.list + data.intervalW * data.list + data.cabinetW + data.intervalW), 0, 0);
  468. WayFindingManager.Instance.SetLine(leftPos, rightPos);
  469. SaveAllData();
  470. isInit = true;
  471. }
  472. public void SettingCameraFar()
  473. {
  474. OpenXRCamera.Instance.head.GetComponent<Camera>().farClipPlane = data.cameraFar;
  475. }
  476. public void OnTrackingFirst(TagTracking tracking)
  477. {
  478. if(isDataInit)
  479. QueryTagData(tracking);
  480. }
  481. public void OnTrackingStay(TagTracking tracking)
  482. {
  483. }
  484. public void OnTrackingFound(TagTracking tracking)
  485. {
  486. // UILogManager.Instance.SendLogText(2, tracking.TrackId.ToString());
  487. if (isDataInit)
  488. QueryTagData(tracking);
  489. }
  490. public void OnTrackingLost(TagTracking tracking)
  491. {
  492. if (isDataInit)
  493. {
  494. if (foundTracking == tracking)
  495. foundTracking = null;
  496. }
  497. }
  498. private void QueryTagData( TagTracking tracking)
  499. {
  500. if (isDataInit)
  501. {
  502. foundTracking = tracking;
  503. tagData = null;
  504. Debug.Log("DGJ ===> QueryTagData" + data.listTagData.Count);
  505. for (int i = 0; i < data.listTagData.Count; i++)
  506. {
  507. if (data.listTagData[i].id == tracking.TrackId)
  508. {
  509. tagData = data.listTagData[i];
  510. SynPlayerTransform.Instance.transform.SetParent(tracking.transform);
  511. break;
  512. }
  513. }
  514. }
  515. //if (state)
  516. //{
  517. // for (int i = 0; i < listEditorTag.Count; i++)
  518. // {
  519. // listEditorTag[i].gameObject.SetActive(!state);
  520. // if (listEditorTag[i].id == tracking.TrackId)
  521. // listEditorTag[i].gameObject.SetActive(true);
  522. // }
  523. //}
  524. }
  525. bool state = false;
  526. public void EditorTag(Text text)
  527. {
  528. text.text = state ? "打开" : "关闭";
  529. text.text += "场景编辑";
  530. state = !state;
  531. DragManager.Instance.state = state;
  532. cubeY.SetActive(state);
  533. for (int i = 0; i < listObjes.Count; i++)
  534. {
  535. listObjes[i].MeshState(state);
  536. }
  537. if (!state && foundTracking!=null)
  538. {
  539. for (int i = 0; i < listEditorTag.Count; i++)
  540. {
  541. listEditorTag[i].gameObject.SetActive(state);
  542. }
  543. for (int i = 0; i < data.listTagData.Count; i++)
  544. {
  545. //data.listTagData[i].offestPos = data.listTagData[i].tagModel.localPosition;
  546. //data.listTagData[i].offestrot = data.listTagData[i].tagModel.localEulerAngles;
  547. for (int j = 0; j < listEditorTag.Count; j++)
  548. {
  549. if (listEditorTag[j].id == data.listTagData[i].id)
  550. {
  551. //data.listTagData[i].offestPos+= listEditorTag[j].transform.localPosition;
  552. //data.listTagData[i].offestrot+= listEditorTag[j].transform.localEulerAngles;
  553. transform.SetParent(listEditorTag[j].transform.parent);
  554. data.listTagData[i].offestPos = transform.localPosition;
  555. data.listTagData[i].offestrot = transform.localEulerAngles;
  556. transform.parent = null;
  557. Debug.Log("DGJ ===> 保存 Tag " + listEditorTag[j].id);
  558. }
  559. }
  560. }
  561. UpdataTagData tagData = new UpdataTagData();
  562. tagData.listTagData = data.listTagData;
  563. string jsonDate = JsonConvert.SerializeObject(tagData);
  564. Debug.Log(jsonDate);
  565. HttpTool.Instance.Post(HttpActionLang.updateTag, jsonDate, UpdateTagCallBack);
  566. selectTOldPos = Vector3.zero;
  567. selectTOldRot = Vector3.zero;
  568. DragManager.Instance.triggerState = TriggerState.No;
  569. selectTrigger = null;
  570. }
  571. if(!state)
  572. {
  573. SaveAllData();
  574. }
  575. }
  576. private void UpdateTagCallBack(string msg)
  577. {
  578. Debug.Log(msg);
  579. JObject json = JObject.Parse(msg);
  580. if (json["code"].ToString() == "200")
  581. {
  582. Debug.Log(" 更新场景Tag参数成功 ");
  583. }
  584. else
  585. {
  586. Debug.LogError(" 更新场景Tag参数出错 !!! " + HttpActionLang.updateCabinet);
  587. }
  588. }
  589. public void SaveAllData()
  590. {
  591. PlayerPrefs.SetString("MachineRoomTagData", JsonConvert.SerializeObject(data.listTagData));
  592. PlayerPrefs.SetString("MachineRoomCabinetData", JsonConvert.SerializeObject(data.listEquipmentData));
  593. PlayerPrefs.SetString("MachineRoomData", JsonConvert.SerializeObject(data));
  594. Debug.Log(" 保存成功 " + JsonConvert.SerializeObject(data));
  595. }
  596. private void SaveData()
  597. {
  598. if(data!=null)
  599. {
  600. string _str = JsonConvert.SerializeObject(data);
  601. System.IO.Directory.CreateDirectory(Application.persistentDataPath+"/Data");
  602. string NowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(" ", "_").Replace("/", "_").Replace(":", "_");
  603. Debug.Log(Application.persistentDataPath + "/Data");
  604. using (System.IO.StreamWriter writer = System.IO.File.CreateText(Application.persistentDataPath + "/Data" + "/"+ NowTime + "_data.txt"))
  605. {
  606. writer.Write(_str);
  607. //writer.
  608. }
  609. //UnityEditor.AssetDatabase.Refresh();
  610. }
  611. }
  612. private void OnDisable()
  613. {
  614. //PlayerPrefs.SetString("MachineRoomTagData", JsonConvert.SerializeObject(data.listTagData));
  615. //PlayerPrefs.SetString("MachineRoomCabinetData", JsonConvert.SerializeObject(data.listEquipmentData));
  616. //PlayerPrefs.SetString("MachineRoomData", JsonConvert.SerializeObject(data));
  617. // SaveData();
  618. }
  619. }
  620. public class UpdataTagData
  621. {
  622. public UpdataTagData()
  623. {
  624. listTagData = new List<MachineRoomTagData>();
  625. }
  626. public List<MachineRoomTagData> listTagData { get; set; }
  627. }