EditorPanel.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using QFramework;
  4. using System.Collections.Generic;
  5. using UniRx;
  6. using System.Linq;
  7. using System.IO;
  8. using System;
  9. using LitJson;
  10. namespace QFramework.MREditor
  11. {
  12. public enum UIEditorEvent
  13. {
  14. Start = QMgrID.UI,
  15. OnUIOpenElenemt,
  16. OnAddSpoitObj,
  17. OnSelectObjName,
  18. OnSaveDataSetting,
  19. OnRemoveDataSetting,
  20. OnAddNewMaterial,
  21. }
  22. public class OnUIOpenElenemt : QMsg
  23. {
  24. public bool state;
  25. public OnUIOpenElenemt(bool state) : base((int)UIEditorEvent.OnUIOpenElenemt)
  26. {
  27. this.state = state;
  28. }
  29. }
  30. public class OnAddSpoitObj : QMsg
  31. {
  32. public string path;
  33. public OnAddSpoitObj(string path) : base((int)UIEditorEvent.OnAddSpoitObj)
  34. {
  35. this.path = path;
  36. }
  37. }
  38. public class OnSelectObjName : QMsg
  39. {
  40. public string spoitName;
  41. public string Name;
  42. public string CMVName;
  43. public OnSelectObjName(string Name, string CMVName, string spoitName) : base((int)UIEditorEvent.OnSelectObjName)
  44. {
  45. this.Name = Name;
  46. this.CMVName = CMVName;
  47. this.spoitName = spoitName;
  48. }
  49. }
  50. public class OnSaveDataSetting : QMsg
  51. {
  52. public Vector3 pos;
  53. public Vector3 rot;
  54. public Vector3 scale;
  55. public string name;
  56. public OnSaveDataSetting(string name, Vector3 pos, Vector3 rot, Vector3 scale) : base((int)UIEditorEvent.OnSaveDataSetting)
  57. {
  58. this.name = name;
  59. this.pos = pos;
  60. this.rot = rot;
  61. this.scale = scale;
  62. }
  63. }
  64. public class OnRemoveDataSetting : QMsg
  65. {
  66. public string name;
  67. public OnRemoveDataSetting(string name) : base((int)UIEditorEvent.OnRemoveDataSetting)
  68. {
  69. this.name = name;
  70. }
  71. }
  72. public class OnAddNewMaterial : QMsg
  73. {
  74. public CompositeMaterialValue newMaterial;
  75. public OnAddNewMaterial(CompositeMaterialValue objValue) : base((int)UIEditorEvent.OnAddNewMaterial)
  76. {
  77. this.newMaterial = objValue;
  78. }
  79. }
  80. public class EditorPanelData : UIPanelData
  81. {
  82. public SceneValue SceneValue = new SceneValue();
  83. public List<CompositeMaterialValue> listLocalMaterials = new List<CompositeMaterialValue>();
  84. public List<CompositeMaterialValue> listUpLoadMaterials = new List<CompositeMaterialValue>();
  85. }
  86. public partial class EditorPanel : UIPanel
  87. {
  88. private Transform selectObj;
  89. private Transform selectCMVObj;
  90. private GameObject selectSpoit;
  91. public Dictionary<string, List<GameObject>> dicObjs;
  92. public Dictionary<string, List<GameObject>> dicCMVOjbes;
  93. public Dictionary<string, SelectBJImage> dicSelectBackImage;
  94. protected override void ProcessMsg(int eventId, QMsg msg)
  95. {
  96. Debug.Log(eventId);
  97. switch ((UIEditorEvent)eventId)
  98. {
  99. case UIEditorEvent.Start:
  100. break;
  101. case UIEditorEvent.OnUIOpenElenemt:
  102. var onUIOpenElenemt = msg as OnUIOpenElenemt;
  103. Debug.Log(onUIOpenElenemt.state);
  104. OpenElenemt(onUIOpenElenemt.state);
  105. break;
  106. case UIEditorEvent.OnAddSpoitObj:
  107. var OnAddSpoitObj = msg as OnAddSpoitObj;
  108. Debug.Log(OnAddSpoitObj.path +" ?????");
  109. break;
  110. case UIEditorEvent.OnSelectObjName:
  111. var OnSelectObjName = msg as OnSelectObjName;
  112. Debug.Log(OnSelectObjName.Name);
  113. SelectedObj(OnSelectObjName.Name, OnSelectObjName.spoitName);
  114. Debug.Log("OnSelectObjName");
  115. break;
  116. case UIEditorEvent.OnSaveDataSetting:
  117. var OnSaveDataSetting = msg as OnSaveDataSetting;
  118. Debug.Log(OnSaveDataSetting.name);
  119. // SaveData(OnSaveDataSetting.name, OnSaveDataSetting.pos, OnSaveDataSetting.rot, OnSaveDataSetting.scale);
  120. SaveData(OnSaveDataSetting.name);
  121. break;
  122. case UIEditorEvent.OnRemoveDataSetting:
  123. var OnRemoveDataSetting = msg as OnRemoveDataSetting;
  124. RemoveData();
  125. break;
  126. case UIEditorEvent.OnAddNewMaterial:
  127. var OnAddNewMaterial = msg as OnAddNewMaterial;
  128. Debug.Log(OnAddNewMaterial.newMaterial);
  129. // AddMaterialObj(OnAddNewMaterial.newMaterial);
  130. AddCMaterialObj(OnAddNewMaterial.newMaterial);
  131. break;
  132. }
  133. }
  134. protected override void OnInit(IUIData uiData = null)
  135. {
  136. mData = uiData as EditorPanelData ?? new EditorPanelData();
  137. selectObj = null;
  138. selectCMVObj = null;
  139. selectSpoit = null;
  140. dicObjs = new Dictionary<string, List<GameObject>>();
  141. // dicCMVOjbes = new Dictionary<string, List<GameObject>>();
  142. dicSelectBackImage = new Dictionary<string, SelectBJImage>();
  143. RegisterEvent(UIEditorEvent.OnUIOpenElenemt);
  144. RegisterEvent(UIEditorEvent.OnAddSpoitObj);
  145. RegisterEvent(UIEditorEvent.OnSelectObjName);
  146. RegisterEvent(UIEditorEvent.OnSaveDataSetting);
  147. RegisterEvent(UIEditorEvent.OnRemoveDataSetting);
  148. RegisterEvent(UIEditorEvent.OnAddNewMaterial);
  149. Debug.Log(mData.listUpLoadMaterials.Count);
  150. try
  151. {
  152. UIAddMaterial.Initialized(mData.listLocalMaterials, mData.listUpLoadMaterials, SingleMaterial);
  153. UIEditor.Initialized(mData.SceneValue.listSpoit);
  154. UISpoits.Initialized(mData.SceneValue.listSpoit, SpoitBtn, MaterialBtn, UIMaterials);
  155. UISpoits.Hide();
  156. }
  157. catch (Exception )
  158. {
  159. ErrorLogPanel.Instance.Show(" UI模块出现未知错误 ");
  160. }
  161. //UIMaterials.Hide();
  162. try
  163. {
  164. List<SpoitValue> listSpoit = new List<SpoitValue>();
  165. mData.SceneValue.listSpoit.ForEach(item =>
  166. {
  167. // Debug.Log(item.name);
  168. listSpoit.Add(item);
  169. // LoadSpoitObj(item.name, item);
  170. });
  171. SpoitValue spoit = null;
  172. for (int i = 0; i < listSpoit.Count; i++)
  173. {
  174. for (int j = 0; j < listSpoit.Count; j++)
  175. {
  176. if (listSpoit[i].id < listSpoit[j].id)
  177. {
  178. spoit = listSpoit[i];
  179. listSpoit[i] = listSpoit[j];
  180. listSpoit[j] = spoit;
  181. spoit = null;
  182. }
  183. }
  184. }
  185. listSpoit.ForEach(item => { Debug.Log(item.name + " " + item.id); LoadSpoitObj(item.name, item); });
  186. }
  187. catch (Exception)
  188. {
  189. ErrorLogPanel.Instance.Show(" 初始化场景信息出现错误");
  190. }
  191. }
  192. protected override void OnOpen(IUIData uiData = null)
  193. {
  194. //transform.parent = GameObject.Find("Canvas").transform;
  195. //RectTransform rect = transform.GetComponent<RectTransform>();
  196. //rect.localPosition = Vector3.zero;
  197. //rect.localScale = Vector3.one;
  198. transform.parent.eulerAngles = new Vector3(30, 0, 0);
  199. }
  200. protected override void OnShow()
  201. {
  202. if (selectSpoit != null)
  203. selectSpoit.SetActive(true);
  204. gameObject.SetActive(true);
  205. }
  206. protected override void OnHide()
  207. {
  208. foreach (var item in dicObjs)
  209. {
  210. item.Value[0].SetActive(false);
  211. }
  212. if (selectSpoit != null)
  213. selectSpoit.SetActive(false);
  214. gameObject.SetActive(false);
  215. }
  216. protected override void OnClose()
  217. {
  218. }
  219. public void OpenElenemt(bool state)
  220. {
  221. if (state)
  222. {
  223. UIEditor.Show();
  224. UIAddMaterial.Close();
  225. }
  226. else
  227. {
  228. UIEditor.Close();
  229. UIAddMaterial.Show();
  230. }
  231. }
  232. /// <summary>
  233. /// 加载景点
  234. /// </summary>
  235. /// <param name="name"></param>
  236. /// <param name="spoit"></param>
  237. public void LoadSpoitObj(string name, SpoitValue spoit)
  238. {
  239. dicObjs.Add(spoit.name, new List<GameObject>());
  240. GameObject target = new GameObject(spoit.name + "Target");
  241. GameObject targetShow = new GameObject("TargetShowObj");
  242. GameObject spoitObj = new GameObject(spoit.name);
  243. spoitObj.transform.parent = target.transform;
  244. spoitObj.transform.LocalIdentity();
  245. targetShow.transform.parent = target.transform;
  246. targetShow.transform.LocalIdentity();
  247. VuforialTargetMove vuforialTarget = target.AddComponent<VuforialTargetMove>();
  248. vuforialTarget.isClose = true;
  249. vuforialTarget.showObjs.Add(spoitObj.transform);
  250. vuforialTarget.listObjs.Add(targetShow.AddComponent<TargetShowObj>());
  251. VuforialControl.Instance.list_Target.Add(vuforialTarget);
  252. dicObjs[spoit.name].Add(spoitObj);
  253. List<CMaterialValueShow> allMaterial = new List<CMaterialValueShow>();
  254. spoit.material.ForEach(item =>
  255. {
  256. Debug.Log(item.name);
  257. LoadCMaterialObj(item, spoitObj);
  258. });
  259. spoitObj.SetActive(false);
  260. Debug.Log(spoit.name+"AAA");
  261. //SelectedObj(name, spoit.Name);
  262. SetObjMaterial(spoitObj, spoit.spoitTf);
  263. }
  264. /// <summary>
  265. /// 加载组合素材
  266. /// </summary>
  267. /// <param name="cMValue"></param>
  268. /// <param name="spoitObj"></param>
  269. public void LoadCMaterialObj(CompositeMaterialValue cMValue, GameObject spoitObj)
  270. {
  271. GameObject cMVObj = new GameObject(cMValue.name);
  272. cMVObj.transform.parent = spoitObj.transform;
  273. cMVObj.transform.LocalIdentity();
  274. CMaterialValueShow cMVShow = cMVObj.AddComponent<CMaterialValueShow>();
  275. cMVShow.spoitname = spoitObj.name;
  276. cMVShow.cMValue = cMValue;
  277. Debug.Log(cMVShow.name);
  278. dicObjs[spoitObj.name].Add(cMVObj);
  279. SetObjMaterial(cMVObj, cMValue.objectTransform);
  280. //if (cMValue.objectTransform != null)
  281. // cMValue.objectTransform.SetObjectTransform(cMVObj.transform);
  282. //else
  283. // Debug.LogError(cMValue.name +" ObjectTransform is NULL ");
  284. }
  285. public void SetObjMaterial(GameObject obj, ObjectTransform objectData)
  286. {
  287. if (objectData == null)
  288. return;
  289. if (objectData.nowScale == Vector3.zero)
  290. {
  291. if (objectData.startScale == Vector3.zero)
  292. objectData.startScale = Vector3.one;
  293. obj.transform.localPosition = Vector3.zero;
  294. obj.transform.localEulerAngles = Vector3.zero;
  295. obj.transform.localScale = Vector3.one;
  296. }
  297. else
  298. {
  299. obj.transform.localPosition = objectData.nowPos;
  300. obj.transform.localEulerAngles = objectData.nowRot;
  301. obj.transform.localScale = objectData.nowScale;
  302. }
  303. }
  304. /// <summary>
  305. /// 选择物体
  306. /// </summary>
  307. /// <param name="name"></param>
  308. /// <param name="spoitName"></param>
  309. public void SelectedObj(string name, string spoitName)
  310. {
  311. if (!dicObjs.ContainsKey(spoitName))
  312. mData.SceneValue.listSpoit.ForEach(item =>
  313. {
  314. Debug.LogError("未找到 景点 "+ spoitName);
  315. //if (item.Name == spoitName)
  316. // Loader(name, item);
  317. });
  318. else
  319. {
  320. //int i = 0;
  321. //foreach (var item in dicObjs)
  322. //{
  323. // item.Value[0].SetActive(false);
  324. // if (item.Key == spoitName)
  325. // {
  326. // item.Value[0].SetActive(true);
  327. // item.Value[0].transform.parent.position = GameManager.Instance.listEditorBJs[0].transform.position += new Vector3(0, 0, -0.1f);
  328. // item.Value[0].transform.parent.eulerAngles = new Vector3(item.Value[0].transform.parent.eulerAngles.x, GameManager.Instance.listEditorBJs[0].transform.eulerAngles.y, item.Value[0].transform.parent.eulerAngles.z);
  329. // GameManager.Instance.SetImageBJ(i);
  330. // }
  331. // i++;
  332. //}
  333. dicObjs[spoitName].ForEach(item =>
  334. {
  335. Debug.Log(item.name + " "+name);
  336. if (item.name == name)
  337. {
  338. //Debug.Log(selectObj.name);
  339. //if (selectObj != null && selectObj.name != selectSpoit.name)
  340. //{
  341. //// selectObj.GetComponent<SelectBJImage>().SelectBj.SetActive(false);
  342. //}
  343. if(selectObj != null&&dicSelectBackImage.ContainsKey(selectSpoit.name+ selectObj.name))
  344. {
  345. dicSelectBackImage[selectSpoit.name + selectObj.name].SelectObj(false);
  346. }
  347. selectSpoit = dicObjs[spoitName][0];
  348. selectObj = item.transform;
  349. if (selectObj.parent.name == selectSpoit.name)
  350. selectCMVObj = item.transform;
  351. else
  352. selectCMVObj = selectObj.parent;
  353. Debug.Log(selectSpoit.name + " " + selectObj.name);
  354. UIEditor.SelectMaterial(item.transform);
  355. if (dicSelectBackImage.ContainsKey(selectSpoit.name + selectObj.name))
  356. {
  357. dicSelectBackImage[selectSpoit.name + selectObj.name].SelectObj(true);
  358. }
  359. //if (selectObj.name != selectSpoit.name)
  360. //{
  361. // // selectObj.GetComponent<SelectBJImage>().SelectBj.SetActive(true);
  362. //}
  363. }
  364. });
  365. //dicObjs[spoitName].ForEach(item =>
  366. //{
  367. // if (item.name == name)
  368. // {
  369. // selectSpoit = dicObjs[spoitName][0];
  370. // selectObj = item.transform;
  371. // UIEditor.SelectMaterial(item.transform);
  372. // }
  373. //});
  374. }
  375. }
  376. public void SelectSpoitObj(string name)
  377. {
  378. // Debug.Log(name + "@@@@@@");
  379. UISpoits.SelectSpoitObj(name);
  380. SelectedObj(name, name);
  381. HttpSocket.Instance.SendIpToPointTrigger(name);
  382. }
  383. /// <summary>
  384. /// 添加组合素材
  385. /// </summary>
  386. /// <param name="value"></param>
  387. public void AddCMaterialObj(CompositeMaterialValue value)
  388. {
  389. if (selectSpoit.IsNull())
  390. return;
  391. UIMaterials.AddMaterial(selectSpoit.name, value, MaterialBtn);
  392. AddData(value);
  393. LoadCMaterialObj(value, selectSpoit);
  394. }
  395. /// <summary>
  396. /// 保存数据
  397. /// </summary>
  398. /// <param name="name"> 选中的物体名 </param>
  399. /// <param name="pos"> 位置 </param>
  400. /// <param name="rot"> 旋转 </param>
  401. /// <param name="scale"> 尺寸 </param>
  402. public void SaveData(string name, Vector3 pos, Vector3 rot, Vector3 scale)
  403. {
  404. if (selectObj == null || selectSpoit==null)
  405. return;
  406. // selectCMVObj = new GameObject("样式测试").transform;
  407. GameManager.Instance.text2.text = selectObj.name + " " + name + " " + selectCMVObj.name + " " + selectSpoit.name;
  408. GameManager.Instance.text4.text = "准备保存";
  409. Debug.Log(name + " " + selectObj.name + " "+selectCMVObj.name +" "+selectSpoit.name);
  410. SpoitValue spoitValue = null;
  411. //for (int i = 0; i < mData.SceneValue.listSpoit.Count; i++)
  412. //{
  413. // if (mData.SceneValue.listSpoit[i].name == selectSpoit.name)
  414. // {
  415. // if (selectSpoit.name == selectObj.name) // 保存的是景点属性
  416. // {
  417. // Debug.Log(" 景点已保存 ");
  418. // mData.SceneValue.listSpoit[i].spoitTf.nowPos = pos;
  419. // mData.SceneValue.listSpoit[i].spoitTf.nowRot = rot;
  420. // if (scale == Vector3.zero)
  421. // scale = mData.SceneValue.listSpoit[i].spoitTf.startScale;
  422. // mData.SceneValue.listSpoit[i].spoitTf.nowScale = scale;
  423. // // mData.SceneValue.listSpoit[i].updateTime = DateTime.Now;
  424. // break;
  425. // }
  426. // spoitValue = mData.SceneValue.listSpoit[i];
  427. // break;
  428. // }
  429. //}
  430. //if (spoitValue != null)
  431. //{
  432. // for (int i = 0; i < spoitValue.material.Count; i++)
  433. // {
  434. // if (spoitValue.material[i].name == selectCMVObj.name)
  435. // {
  436. // if (spoitValue.material[i].name == selectObj.name)
  437. // {
  438. // Debug.Log(" 组合素材属性已保存 ");
  439. // spoitValue.material[i].objectTransform.nowPos = pos;
  440. // spoitValue.material[i].objectTransform.nowRot = rot;
  441. // if (scale == Vector3.zero)
  442. // scale = spoitValue.material[i].objectTransform.startScale;
  443. // spoitValue.material[i].objectTransform.nowScale = scale;
  444. // break;
  445. // }
  446. // for (int j = 0; j < spoitValue.material[i].materialList.Count; j++)
  447. // {
  448. // if (spoitValue.material[i].materialList[j].name == selectObj.name)
  449. // {
  450. // Debug.Log(" 素材已保存 ");
  451. // spoitValue.material[i].materialList[j].ObjectTransform.nowPos = pos;
  452. // spoitValue.material[i].materialList[j].ObjectTransform.nowRot = rot;
  453. // if (scale == Vector3.zero)
  454. // scale = spoitValue.material[i].materialList[j].ObjectTransform.startScale;
  455. // spoitValue.material[i].materialList[j].ObjectTransform.nowScale = scale;
  456. // break;
  457. // }
  458. // }
  459. // break;
  460. // }
  461. // }
  462. // for (int i = 0; i < mData.SceneValue.listSpoit.Count; i++)
  463. // {
  464. // if (mData.SceneValue.listSpoit[i].name == spoitValue.name)
  465. // {
  466. // mData.SceneValue.listSpoit[i] = spoitValue;
  467. // break;
  468. // }
  469. // }
  470. //}
  471. for (int i = 0; i < mData.SceneValue.listSpoit.Count; i++)
  472. {
  473. if (mData.SceneValue.listSpoit[i].name == selectSpoit.name)
  474. {
  475. Debug.Log(" 景点已保存 ");
  476. mData.SceneValue.listSpoit[i].spoitTf.nowPos = pos;
  477. mData.SceneValue.listSpoit[i].spoitTf.nowRot = rot;
  478. if (scale == Vector3.zero)
  479. scale = mData.SceneValue.listSpoit[i].spoitTf.startScale;
  480. mData.SceneValue.listSpoit[i].spoitTf.nowScale = scale;
  481. // mData.SceneValue.listSpoit[i].updateTime = DateTime.Now;
  482. spoitValue = mData.SceneValue.listSpoit[i];
  483. break;
  484. }
  485. }
  486. if (spoitValue != null)
  487. {
  488. for (int i = 0; i < spoitValue.material.Count; i++)
  489. {
  490. if (spoitValue.material[i].name == selectCMVObj.name)
  491. {
  492. Debug.Log(" 组合素材属性已保存 ");
  493. spoitValue.material[i].objectTransform.nowPos = pos;
  494. spoitValue.material[i].objectTransform.nowRot = rot;
  495. if (scale == Vector3.zero)
  496. scale = spoitValue.material[i].objectTransform.startScale;
  497. spoitValue.material[i].objectTransform.nowScale = scale;
  498. break;
  499. for (int j = 0; j < spoitValue.material[i].materialList.Count; j++)
  500. {
  501. Debug.Log(" 素材已保存 ");
  502. spoitValue.material[i].materialList[j].ObjectTransform.nowPos = pos;
  503. spoitValue.material[i].materialList[j].ObjectTransform.nowRot = rot;
  504. if (scale == Vector3.zero)
  505. scale = spoitValue.material[i].materialList[j].ObjectTransform.startScale;
  506. spoitValue.material[i].materialList[j].ObjectTransform.nowScale = scale;
  507. break;
  508. }
  509. break;
  510. }
  511. }
  512. for (int i = 0; i < mData.SceneValue.listSpoit.Count; i++)
  513. {
  514. if (mData.SceneValue.listSpoit[i].name == spoitValue.name)
  515. {
  516. mData.SceneValue.listSpoit[i] = spoitValue;
  517. break;
  518. }
  519. }
  520. }
  521. }
  522. public void SaveData(string name)
  523. {
  524. List<GameObject> list_Material;
  525. list_Material = dicObjs[selectSpoit.name];
  526. Debug.Log(" SelectSpoit Name : " + selectSpoit.name);
  527. // list_Material.ForEach(item =>
  528. //{
  529. // SaveData(item.name, item.transform.localPosition, item.transform.localEulerAngles, item.transform.localScale);
  530. //});
  531. SaveData(list_Material);
  532. GameManager.Instance.Save(mData.SceneValue);
  533. }
  534. private void SaveData(List<GameObject> list_Material)
  535. {
  536. SpoitValue spoitValue = null;
  537. for (int i = 0; i < mData.SceneValue.listSpoit.Count; i++)
  538. {
  539. if (mData.SceneValue.listSpoit[i].name == selectSpoit.name)
  540. {
  541. Debug.Log(" 景点已保存 ");
  542. mData.SceneValue.listSpoit[i].spoitTf.nowPos = list_Material[0].transform.localPosition;
  543. mData.SceneValue.listSpoit[i].spoitTf.nowRot = list_Material[0].transform.localEulerAngles;
  544. if (list_Material[0].transform.localScale == Vector3.zero)
  545. list_Material[0].transform.localScale = mData.SceneValue.listSpoit[i].spoitTf.startScale;
  546. mData.SceneValue.listSpoit[i].spoitTf.nowScale = list_Material[0].transform.localScale;
  547. // mData.SceneValue.listSpoit[i].updateTime = DateTime.Now;
  548. spoitValue = mData.SceneValue.listSpoit[i];
  549. break;
  550. }
  551. }
  552. Transform material;
  553. Debug.Log(" ****** "+spoitValue.name);
  554. if(spoitValue != null)
  555. {
  556. for (int i = 0; i < spoitValue.material.Count; i++)
  557. {
  558. material = FindMaterial(list_Material, spoitValue.material[i].name);
  559. if(material!=null)
  560. {
  561. Debug.Log(" 组合素材已保存 ");
  562. spoitValue.material[i].objectTransform.nowPos = material.localPosition;
  563. spoitValue.material[i].objectTransform.nowRot = material.localEulerAngles;
  564. spoitValue.material[i].objectTransform.nowScale = material.localScale;
  565. }
  566. for (int j = 0; j < spoitValue.material[i].materialList.Count; j++)
  567. {
  568. material = FindMaterial(list_Material, spoitValue.material[i].materialList[j].name);
  569. if (material != null)
  570. {
  571. Debug.Log(" 素材已保存 ");
  572. spoitValue.material[i].materialList[j].ObjectTransform.nowPos = material.localPosition;
  573. spoitValue.material[i].materialList[j].ObjectTransform.nowRot = material.localEulerAngles;
  574. spoitValue.material[i].materialList[j].ObjectTransform.nowScale = material.localScale;
  575. }
  576. }
  577. }
  578. }
  579. }
  580. private Transform FindMaterial(List<GameObject> list_Material, string name )
  581. {
  582. for (int i = 1; i < list_Material.Count; i++)
  583. {
  584. Debug.Log(list_Material[i].name + " " + name);
  585. if (list_Material[i].name == name)
  586. return list_Material[i].transform;
  587. }
  588. return null;
  589. }
  590. /// <summary>
  591. /// 移除选中数据
  592. /// </summary>
  593. public void RemoveData()
  594. {
  595. if (selectObj == null)
  596. return;
  597. if (selectSpoit.name == selectObj.name)
  598. return;
  599. SpoitValue spoitValue = null;
  600. for (int i = 0; i < mData.SceneValue.listSpoit.Count; i++)
  601. {
  602. if (mData.SceneValue.listSpoit[i].name == selectSpoit.name)
  603. {
  604. //if (selectSpoit.name == selectObj.name)
  605. //{
  606. // mData.SceneValue.listSpoit.Remove(mData.SceneValue.listSpoit[i]);
  607. // break;
  608. //}
  609. spoitValue = mData.SceneValue.listSpoit[i];
  610. break;
  611. }
  612. }
  613. if (spoitValue != null)
  614. {
  615. for (int i = 0; i < spoitValue.material.Count; i++)
  616. {
  617. if (spoitValue.material[i].name == selectObj.name)
  618. {
  619. spoitValue.material.Remove(spoitValue.material[i]);
  620. break;
  621. }
  622. for (int j = 0; j < spoitValue.material[i].materialList.Count; j++)
  623. {
  624. if (spoitValue.material[i].materialList[j].name == selectObj.name)
  625. {
  626. spoitValue.material[i].materialList.Remove(spoitValue.material[i].materialList[j]);
  627. break;
  628. }
  629. }
  630. }
  631. for (int i = 0; i < mData.SceneValue.listSpoit.Count; i++)
  632. {
  633. if (mData.SceneValue.listSpoit[i].name == spoitValue.name)
  634. {
  635. mData.SceneValue.listSpoit[i] = spoitValue;
  636. break;
  637. }
  638. }
  639. }
  640. UIMaterials.RemoveMaterials(selectSpoit.name+ selectObj.name);
  641. selectObj.gameObject.SetActive(false);
  642. selectObj = null;
  643. GameManager.Instance.Save(mData.SceneValue);
  644. }
  645. //public void AddData(MaterialObjValue value)
  646. //{
  647. // for (int i = 0; i < mData.SceneValue.listSpoit.Count; i++)
  648. // {
  649. // if(mData.SceneValue.listSpoit[i].name == selectObj.name)
  650. // {
  651. // mData.SceneValue.listSpoit[i].listMaterial.Add(value);
  652. // GameManager.Instance.Save(mData.SceneValue);
  653. // break;
  654. // }
  655. // }
  656. //}
  657. /// <summary>
  658. /// 新添加数据
  659. /// </summary>
  660. /// <param name="value"></param>
  661. public void AddData(CompositeMaterialValue value)
  662. {
  663. for (int i = 0; i < mData.SceneValue.listSpoit.Count; i++)
  664. {
  665. if (mData.SceneValue.listSpoit[i].name == selectObj.name)
  666. {
  667. Debug.Log(JsonMapper.ToJson( mData.SceneValue.listSpoit[i]));
  668. mData.SceneValue.listSpoit[i].material.Add(value);
  669. Debug.Log(JsonMapper.ToJson(mData.SceneValue.listSpoit[i]));
  670. GameManager.Instance.Save(mData.SceneValue);
  671. break;
  672. }
  673. }
  674. }
  675. }
  676. }