UIManager.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class UIManager : MonoBehaviour
  5. {
  6. public RectTransform pos_Panel;
  7. public RectTransform rot_Panel;
  8. public RectTransform scale_Panel;
  9. public Transform targetObj;
  10. public Dictionary<string, List<Vector3>> dicStep;
  11. private void Start()
  12. {
  13. // targetObj = null;
  14. dicStep = new Dictionary<string, List<Vector3>>();
  15. dicStep.Add("PosStep", new List<Vector3>());
  16. dicStep.Add("RotStep", new List<Vector3>());
  17. dicStep.Add("ScaleStep", new List<Vector3>());
  18. }
  19. /// <summary>
  20. /// 切换显示景点
  21. /// </summary>
  22. public void CustTargetObj()
  23. {
  24. targetObj = null;
  25. dicStep.Clear();
  26. }
  27. /// <summary>
  28. /// 选择显示景点
  29. /// </summary>
  30. /// <param name="obj"></param>
  31. public void SelectTargetObj(Transform obj)
  32. {
  33. targetObj = obj;
  34. dicStep.Clear();
  35. dicStep = new Dictionary<string, List<Vector3>>();
  36. dicStep.Add("PosStep", new List<Vector3>());
  37. dicStep.Add("RotStep", new List<Vector3>());
  38. dicStep.Add("ScaleStep", new List<Vector3>());
  39. }
  40. /// <summary>
  41. /// 根据传进来的Json数据,生成场景列表和每个场景对应的显示物体列表
  42. /// 默认是在扫图模式下修改
  43. /// 点云模式下直接加载点云模型修改点云模型内物体的位置信息
  44. /// </summary>
  45. public void Initiative()
  46. {
  47. }
  48. public void SelectPanel(string togName)
  49. {
  50. switch (togName)
  51. {
  52. case "pos_tog":
  53. pos_Panel.gameObject.SetActive(true);
  54. rot_Panel.gameObject.SetActive(false);
  55. scale_Panel.gameObject.SetActive(false);
  56. break;
  57. case "rot_tog":
  58. pos_Panel.gameObject.SetActive(false);
  59. rot_Panel.gameObject.SetActive(true);
  60. scale_Panel.gameObject.SetActive(false);
  61. break;
  62. case "scale_tog":
  63. pos_Panel.gameObject.SetActive(false);
  64. rot_Panel.gameObject.SetActive(false);
  65. scale_Panel.gameObject.SetActive(true);
  66. break;
  67. default:
  68. break;
  69. }
  70. }
  71. public void SettingPos(string setName)
  72. {
  73. Debug.Log("1");
  74. if (targetObj == null)
  75. return;
  76. Debug.Log(setName+"11");
  77. Vector3 pos = Vector3.zero;
  78. switch (setName)
  79. {
  80. case "addX":
  81. pos.x = 0.2f;
  82. break;
  83. case "subX":
  84. pos.x = -0.2f;
  85. break;
  86. case "addY":
  87. pos.y = 0.1f;
  88. break;
  89. case "subY":
  90. pos.y = -0.1f;
  91. break;
  92. case "addZ":
  93. pos.z = 0.1f;
  94. break;
  95. case "subZ":
  96. pos.z = -0.1f;
  97. break;
  98. default:
  99. break;
  100. }
  101. dicStep["PosStep"].Add(targetObj.localPosition);
  102. Debug.Log(targetObj.localPosition);
  103. targetObj.localPosition += pos;
  104. Debug.Log(targetObj.localPosition);
  105. Debug.Log("3");
  106. }
  107. public void SettingRot(string setName)
  108. {
  109. if (targetObj == null)
  110. return;
  111. Vector3 rot = Vector3.zero;
  112. switch (setName)
  113. {
  114. case "addX":
  115. rot.x = 5f;
  116. break;
  117. case "subX":
  118. rot.x = -5f;
  119. break;
  120. case "addY":
  121. rot.y = 5f;
  122. break;
  123. case "subY":
  124. rot.y = -5f;
  125. break;
  126. case "addZ":
  127. rot.z = 5f;
  128. break;
  129. case "subZ":
  130. rot.z = -5f;
  131. break;
  132. default:
  133. break;
  134. }
  135. dicStep["RotStep"].Add(targetObj.localEulerAngles);
  136. targetObj.localEulerAngles += rot;
  137. }
  138. public void SettingScale(string setName)
  139. {
  140. if (targetObj == null)
  141. return;
  142. Vector3 scale = Vector3.zero;
  143. switch (setName)
  144. {
  145. case "ADD":
  146. scale = new Vector3(0.1f, 0.1f, 0.1f);
  147. break;
  148. case "Sub":
  149. scale = new Vector3(-0.1f, -0.1f, -0.1f);
  150. break;
  151. default:
  152. break;
  153. }
  154. dicStep["ScaleStep"].Add(targetObj.localScale);
  155. targetObj.localScale += scale;
  156. }
  157. public void Revocation(string TName)
  158. {
  159. Debug.Log("Revocation:"+ TName);
  160. switch (TName)
  161. {
  162. case "pos":
  163. if (dicStep["PosStep"].Count < 1)
  164. return;
  165. targetObj.localPosition = dicStep["PosStep"][dicStep["PosStep"].Count - 1];
  166. dicStep["PosStep"].RemoveAt(dicStep["PosStep"].Count - 1);
  167. break;
  168. case "rot":
  169. if (dicStep["RotStep"].Count < 1)
  170. return;
  171. targetObj.localEulerAngles = dicStep["RotStep"][dicStep["RotStep"].Count - 1];
  172. dicStep["RotStep"].RemoveAt(dicStep["RotStep"].Count - 1);
  173. break;
  174. case "scale":
  175. if (dicStep["ScaleStep"].Count < 1)
  176. return;
  177. targetObj.localScale = dicStep["ScaleStep"][dicStep["ScaleStep"].Count - 1];
  178. dicStep["ScaleStep"].RemoveAt(dicStep["ScaleStep"].Count - 1);
  179. break;
  180. default:
  181. break;
  182. }
  183. }
  184. public void InitDicStep(string TName)
  185. {
  186. Debug.Log("Revocation:" + TName);
  187. switch (TName)
  188. {
  189. case "pos":
  190. if (dicStep["PosStep"].Count < 1)
  191. return;
  192. targetObj.localPosition = dicStep["PosStep"][0];
  193. dicStep["PosStep"].Clear();
  194. dicStep["PosStep"] = new List<Vector3>();
  195. break;
  196. case "rot":
  197. if (dicStep["RotStep"].Count < 1)
  198. return;
  199. targetObj.localEulerAngles = dicStep["RotStep"][0];
  200. dicStep["RotStep"].Clear();
  201. dicStep["RotStep"] = new List<Vector3>();
  202. break;
  203. case "scale":
  204. if (dicStep["ScaleStep"].Count < 1)
  205. return;
  206. targetObj.localScale = dicStep["ScaleStep"][0];
  207. dicStep["ScaleStep"].Clear();
  208. dicStep["ScaleStep"] = new List<Vector3>();
  209. break;
  210. default:
  211. break;
  212. }
  213. }
  214. }