UIEditor.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /****************************************************************************
  2. * 2022.1 SK-20211220VCWK
  3. ****************************************************************************/
  4. using System;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. using QFramework;
  9. namespace QFramework.MREditor
  10. {
  11. public partial class UIEditor : UIElement
  12. {
  13. private void Awake()
  14. {
  15. }
  16. protected override void OnBeforeDestroy()
  17. {
  18. }
  19. public void Close()
  20. {
  21. gameObject.SetActive(false);
  22. }
  23. private Transform MaterialObj;
  24. private List<ObjectTData> listAlter;
  25. private List<SpoitValue> listSpoits;
  26. public void Initialized(List<SpoitValue> listSpoits)
  27. {
  28. MaterialObj = null;
  29. this.listSpoits = listSpoits;
  30. listAlter = new List<ObjectTData>();
  31. #region BtnInitialized
  32. UCBtn.onClick.AddListener(() =>
  33. {
  34. if (UCElenemt.gameObject.activeSelf)
  35. return;
  36. UCElenemt.gameObject.SetActive(true);
  37. TicElenemt.gameObject.SetActive(false);
  38. });
  39. TicBtn.onClick.AddListener(() =>
  40. {
  41. if (TicElenemt.gameObject.activeSelf)
  42. return;
  43. UCElenemt.gameObject.SetActive(false);
  44. TicElenemt.gameObject.SetActive(true);
  45. });
  46. RemoveBtn.onClick.AddListener(() =>
  47. {
  48. if (MaterialObj == null)
  49. return;
  50. SendMsg(new OnRemoveDataSetting("SelectObj"));
  51. // 痄壺絞ゴ匼第
  52. });
  53. // RemoveBtn.gameObject.SetActive(false);
  54. AddSize.onClick.AddListener(() =>
  55. {
  56. if (MaterialObj == null)
  57. return;
  58. SaveAlter();
  59. MaterialObj.localScale += new Vector3(MaterialObj.localScale.x / 10.0f, MaterialObj.localScale.y / 10.0f, MaterialObj.localScale.z / 10.0f);
  60. });
  61. SubSize.onClick.AddListener(() =>
  62. {
  63. if (MaterialObj == null)
  64. return;
  65. SaveAlter();
  66. MaterialObj.localScale -= new Vector3(MaterialObj.localScale.x / 10.0f, MaterialObj.localScale.y / 10.0f, MaterialObj.localScale.z / 10.0f);
  67. });
  68. AddRot.GetComponent<SCButton>().onClick.AddListener(() =>
  69. {
  70. if (MaterialObj == null)
  71. return;
  72. SaveAlter();
  73. MaterialObj.localEulerAngles += new Vector3(0, 10, 0);
  74. });
  75. SubRot.GetComponent<SCButton>().onClick.AddListener(() =>
  76. {
  77. if (MaterialObj == null)
  78. return;
  79. SaveAlter();
  80. MaterialObj.localEulerAngles -= new Vector3(0, 10, 0);
  81. });
  82. // SubRot.onClick.AddListener(() =>
  83. // {
  84. // if (MaterialObj == null)
  85. // return;
  86. // SaveAlter();
  87. // MaterialObj.localEulerAngles -= new Vector3(0, 10, 0);
  88. //});
  89. AddX.onClick.AddListener(() =>
  90. {
  91. if (MaterialObj == null)
  92. return;
  93. SaveAlter();
  94. MaterialObj.localPosition -= new Vector3(0.1f, 0, 0);
  95. });
  96. SubX.onClick.AddListener(() =>
  97. {
  98. if (MaterialObj == null)
  99. return;
  100. SaveAlter();
  101. MaterialObj.localPosition += new Vector3(0.1f, 0, 0);
  102. });
  103. AddY.onClick.AddListener(() =>
  104. {
  105. if (MaterialObj == null)
  106. return;
  107. SaveAlter();
  108. MaterialObj.localPosition += new Vector3(0, 0.1f, 0);
  109. });
  110. SubY.onClick.AddListener(() =>
  111. {
  112. if (MaterialObj == null)
  113. return;
  114. SaveAlter();
  115. MaterialObj.localPosition -= new Vector3(0, 0.1f, 0);
  116. });
  117. ADDXBtn.onClick.AddListener(() =>
  118. {
  119. if (MaterialObj == null)
  120. return;
  121. SaveAlter();
  122. MaterialObj.localPosition -= new Vector3(0.1f, 0, 0);
  123. });
  124. SubXBtn.onClick.AddListener(() =>
  125. {
  126. if (MaterialObj == null)
  127. return;
  128. SaveAlter();
  129. MaterialObj.localPosition += new Vector3(0.1f, 0, 0);
  130. });
  131. ADDYBtn.onClick.AddListener(() =>
  132. {
  133. if (MaterialObj == null)
  134. return;
  135. SaveAlter();
  136. MaterialObj.localPosition += new Vector3(0, 0.1f, 0);
  137. });
  138. SubYBtn.onClick.AddListener(() =>
  139. {
  140. if (MaterialObj == null)
  141. return;
  142. SaveAlter();
  143. MaterialObj.localPosition -= new Vector3(0, 0.1f, 0);
  144. });
  145. AddZBtn.onClick.AddListener(() =>
  146. {
  147. if (MaterialObj == null)
  148. return;
  149. SaveAlter();
  150. MaterialObj.localPosition += new Vector3(0, 0, 0.1f);
  151. });
  152. SubZBtn.onClick.AddListener(() =>
  153. {
  154. if (MaterialObj == null)
  155. return;
  156. SaveAlter();
  157. MaterialObj.localPosition -= new Vector3(0, 0, 0.1f);
  158. });
  159. InitiativeBtn.onClick.AddListener(() =>
  160. {
  161. if (MaterialObj == null)
  162. return;
  163. InitMaterialObj();
  164. });
  165. RevocationBtn.onClick.AddListener(() =>
  166. {
  167. if (MaterialObj == null)
  168. return;
  169. MaterialObj.localPosition = listAlter[listAlter.Count - 1].pos;
  170. MaterialObj.localEulerAngles = listAlter[listAlter.Count - 1].rot;
  171. MaterialObj.localScale = listAlter[listAlter.Count - 1].scale;
  172. listAlter.RemoveAt(listAlter.Count - 1);
  173. });
  174. SaveBtn.onClick.AddListener(() =>
  175. {
  176. if (MaterialObj == null)
  177. return;
  178. SendMsg(new OnSaveDataSetting(MaterialObj.name, MaterialObj.localPosition, MaterialObj.localEulerAngles, MaterialObj.localScale));
  179. });
  180. #endregion
  181. }
  182. /// <summary>
  183. /// 恁寁匼第
  184. /// </summary>
  185. /// <param name="MaterialObj"></param>
  186. public void SelectMaterial(Transform MaterialObj)
  187. {
  188. this.MaterialObj = MaterialObj;
  189. listAlter.Clear();
  190. listAlter = new List<ObjectTData>();
  191. }
  192. private void InitMaterialObj()
  193. {
  194. if (MaterialObj == null)
  195. return;
  196. string name = MaterialObj.name;
  197. listAlter.Clear();
  198. listAlter = new List<ObjectTData>();
  199. for (int i = 0; i < listSpoits.Count; i++)
  200. {
  201. if(listSpoits[i].name == name)
  202. {
  203. }
  204. }
  205. //脤梑劓萸睿劓萸囀腔郪磁匼第靡
  206. List<CompositeMaterialValue> listCMV = new List<CompositeMaterialValue>();
  207. for (int i = 0; i < listSpoits.Count; i++)
  208. {
  209. if(listSpoits[i].name ==name)
  210. {
  211. SetObjTransform(MaterialObj, listSpoits[i].spoitTf);
  212. return;
  213. }
  214. for (int j = 0; j < listSpoits[i].material.Count; j++)
  215. {
  216. switch ((MaterialType)listSpoits[i].material[j].type)
  217. {
  218. case MaterialType.NULL:
  219. break;
  220. case MaterialType.Image:
  221. break;
  222. case MaterialType.Video:
  223. break;
  224. case MaterialType.Model:
  225. break;
  226. case MaterialType.Text:
  227. break;
  228. case MaterialType.ImageorViedoAndText:
  229. if (listSpoits[i].material[j].name == name)
  230. {
  231. SetObjTransform(MaterialObj, listSpoits[i].material[j].objectTransform);
  232. return;
  233. }
  234. break;
  235. case MaterialType.ModelAndText:
  236. if (listSpoits[i].material[j].name == name)
  237. {
  238. SetObjTransform(MaterialObj, listSpoits[i].material[j].objectTransform);
  239. return;
  240. }
  241. break;
  242. default:
  243. break;
  244. }
  245. listCMV.Add(listSpoits[i].material[j]);
  246. }
  247. }
  248. //脤梑郪磁匼第囀等跺匼第
  249. for (int i = 0; i < listCMV.Count; i++)
  250. {
  251. for (int j = 0; j < listCMV[i].materialList.Count; j++)
  252. {
  253. if (listCMV[i].materialList[j].name == name)
  254. {
  255. SetObjTransform(MaterialObj, listCMV[i].materialList[j].ObjectTransform);
  256. return;
  257. }
  258. }
  259. }
  260. }
  261. private void SetObjTransform(Transform obj , ObjectTransform objTransform )
  262. {
  263. obj.localPosition = objTransform.startPos;
  264. obj.localEulerAngles = objTransform.startRot;
  265. obj.localScale = objTransform.startScale;
  266. }
  267. private void SaveAlter()
  268. {
  269. ObjectTData data = new ObjectTData();
  270. data.pos = MaterialObj.localPosition;
  271. data.rot = MaterialObj.localEulerAngles;
  272. data.scale = MaterialObj.localScale;
  273. listAlter.Add(data);
  274. }
  275. }
  276. }