AnchorEditorPanel.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class AnchorEditorPanel : MonoBehaviour, EventObserver
  7. {
  8. public event Action<GameObject> OnClickRemoveBtn;
  9. [SerializeField] private Button UCBtn;
  10. [SerializeField] private Button TicBtn;
  11. [SerializeField] private Button RemoveBtn;
  12. [SerializeField] private Image UCElenemt;
  13. [SerializeField] private Button AddSize;
  14. [SerializeField] private Button SubSize;
  15. [SerializeField] private Button SubY;
  16. [SerializeField] private Button AddY;
  17. [SerializeField] private Button SubX;
  18. [SerializeField] private Button AddX;
  19. [SerializeField] private SCButton SubRot;
  20. [SerializeField] private SCButton AddRot;
  21. [SerializeField] private Image TicElenemt;
  22. [SerializeField] private Button ADDXBtn;
  23. [SerializeField] private Button SubXBtn;
  24. [SerializeField] private Button ADDYBtn;
  25. [SerializeField] private Button SubYBtn;
  26. [SerializeField] private Button AddZBtn;
  27. [SerializeField] private Button SubZBtn;
  28. [SerializeField] private Button InitiativeBtn;
  29. [SerializeField] private Button RevocationBtn;
  30. [SerializeField] private Button SaveBtn;
  31. private Transform anchorObj;
  32. /// <summary>
  33. /// 当前物体移动旋转缩放的操作步骤
  34. /// </summary>
  35. private List<objectData> listAlter;
  36. private void Awake()
  37. {
  38. InitEvent();
  39. anchorObj = null;
  40. listAlter = new List<objectData>();
  41. EventManager.Instance.Register(this, EventID.EVENT_3);
  42. }
  43. public void Init()
  44. {
  45. //RemoveBtn.onClick.AddListener(() =>
  46. //{
  47. // Debug.Log(" 移除已取消 ");
  48. //});
  49. }
  50. private void InitEvent()
  51. {
  52. UCBtn.onClick.AddListener(() =>
  53. {
  54. if (UCElenemt.gameObject.activeSelf)
  55. return;
  56. UCElenemt.gameObject.SetActive(true);
  57. TicElenemt.gameObject.SetActive(false);
  58. });
  59. TicBtn.onClick.AddListener(() =>
  60. {
  61. if (TicElenemt.gameObject.activeSelf)
  62. return;
  63. UCElenemt.gameObject.SetActive(false);
  64. TicElenemt.gameObject.SetActive(true);
  65. });
  66. //RemoveBtn.onClick.AddListener(() =>
  67. //{
  68. // if (anchorObj == null)
  69. // return;
  70. // if (anchorObj.tag == "TriggerBox")
  71. // return;
  72. // if (OnClickRemoveBtn != null)
  73. // {
  74. // OnClickRemoveBtn(anchorObj.gameObject);
  75. // }
  76. //});
  77. //RemoveBtn.gameObject.SetActive(false);
  78. AddSize.onClick.AddListener(() =>
  79. {
  80. if (anchorObj == null)
  81. return;
  82. SaveAlter();
  83. anchorObj.localScale += new Vector3(anchorObj.localScale.x / 10.0f, anchorObj.localScale.y / 10.0f, anchorObj.localScale.z / 10.0f);
  84. });
  85. SubSize.onClick.AddListener(() =>
  86. {
  87. if (anchorObj == null)
  88. return;
  89. SaveAlter();
  90. anchorObj.localScale -= new Vector3(anchorObj.localScale.x / 10.0f, anchorObj.localScale.y / 10.0f, anchorObj.localScale.z / 10.0f);
  91. });
  92. AddRot.onClick.AddListener(() =>
  93. {
  94. if (anchorObj == null)
  95. return;
  96. SaveAlter();
  97. anchorObj.localEulerAngles += new Vector3(0, 10, 0);
  98. });
  99. SubRot.onClick.AddListener(() =>
  100. {
  101. if (anchorObj == null)
  102. return;
  103. SaveAlter();
  104. anchorObj.localEulerAngles -= new Vector3(0, 10, 0);
  105. });
  106. AddX.onClick.AddListener(() =>
  107. {
  108. if (anchorObj == null)
  109. return;
  110. SaveAlter();
  111. anchorObj.localPosition -= new Vector3(0.1f, 0, 0);
  112. });
  113. SubX.onClick.AddListener(() =>
  114. {
  115. if (anchorObj == null)
  116. return;
  117. SaveAlter();
  118. anchorObj.localPosition += new Vector3(0.1f, 0, 0);
  119. });
  120. AddY.onClick.AddListener(() =>
  121. {
  122. if (anchorObj == null)
  123. return;
  124. SaveAlter();
  125. anchorObj.localPosition += new Vector3(0, 0.1f, 0);
  126. });
  127. SubY.onClick.AddListener(() =>
  128. {
  129. if (anchorObj == null)
  130. return;
  131. SaveAlter();
  132. anchorObj.localPosition -= new Vector3(0, 0.1f, 0);
  133. });
  134. ADDXBtn.onClick.AddListener(() =>
  135. {
  136. if (anchorObj == null)
  137. return;
  138. SaveAlter();
  139. anchorObj.localPosition -= new Vector3(0.1f, 0, 0);
  140. });
  141. SubXBtn.onClick.AddListener(() =>
  142. {
  143. if (anchorObj == null)
  144. return;
  145. SaveAlter();
  146. anchorObj.localPosition += new Vector3(0.1f, 0, 0);
  147. });
  148. ADDYBtn.onClick.AddListener(() =>
  149. {
  150. if (anchorObj == null)
  151. return;
  152. SaveAlter();
  153. anchorObj.localPosition += new Vector3(0, 0.1f, 0);
  154. });
  155. SubYBtn.onClick.AddListener(() =>
  156. {
  157. if (anchorObj == null)
  158. return;
  159. SaveAlter();
  160. anchorObj.localPosition -= new Vector3(0, 0.1f, 0);
  161. });
  162. AddZBtn.onClick.AddListener(() =>
  163. {
  164. if (anchorObj == null)
  165. return;
  166. SaveAlter();
  167. anchorObj.localPosition += new Vector3(0, 0, 0.1f);
  168. });
  169. SubZBtn.onClick.AddListener(() =>
  170. {
  171. if (anchorObj == null)
  172. return;
  173. SaveAlter();
  174. anchorObj.localPosition -= new Vector3(0, 0, 0.1f);
  175. });
  176. InitiativeBtn.onClick.AddListener(() =>
  177. {
  178. if (anchorObj == null)
  179. return;
  180. InitanchorObj();
  181. });
  182. RevocationBtn.onClick.AddListener(() =>
  183. {
  184. if (anchorObj == null)
  185. return;
  186. if (listAlter.Count >= 1)
  187. {
  188. anchorObj.localPosition = listAlter[listAlter.Count - 1].pos;
  189. anchorObj.localEulerAngles = listAlter[listAlter.Count - 1].rot;
  190. anchorObj.localScale = listAlter[listAlter.Count - 1].scale;
  191. listAlter.RemoveAt(listAlter.Count - 1);
  192. }
  193. });
  194. SaveBtn.onClick.AddListener(() =>
  195. {
  196. if (anchorObj == null)
  197. return;
  198. GameManager.Instance.SaveAnchorObjs( anchorObj.name);
  199. });
  200. }
  201. /// <summary>
  202. /// 选择锚点
  203. /// </summary>
  204. /// <param name="anchorObj"></param>
  205. public void SelectAnchor(Transform anchorObj)
  206. {
  207. if (this.anchorObj != null)
  208. this.anchorObj.GetChild(0).gameObject.SetActive(false);
  209. this.anchorObj = anchorObj;
  210. this.anchorObj.GetChild(0).gameObject.SetActive(true);
  211. listAlter.Clear();
  212. listAlter = new List<objectData>();
  213. }
  214. /// <summary>
  215. /// 初始化素材
  216. /// 只初始化当前素材
  217. /// </summary>
  218. private void InitanchorObj()
  219. {
  220. if (anchorObj == null)
  221. return;
  222. string name = anchorObj.name;
  223. listAlter.Clear();
  224. listAlter = new List<objectData>();
  225. // GameManager.Instance.InitSpoitObjs();
  226. }
  227. private void SaveAlter()
  228. {
  229. objectData data = new objectData();
  230. data.pos = anchorObj.localPosition;
  231. data.rot = anchorObj.localEulerAngles;
  232. data.scale = anchorObj.localScale;
  233. listAlter.Add(data);
  234. }
  235. public void HandleEvent(EventData data)
  236. {
  237. switch (data.ID)
  238. {
  239. case EventID.EVENT_3:
  240. EventData1 data1 = (EventData1)data;
  241. if (data1.SelectObj != null)
  242. {
  243. SelectAnchor(data1.SelectObj.transform);
  244. }
  245. else
  246. {
  247. anchorObj = null;
  248. listAlter.Clear();
  249. }
  250. break;
  251. case EventID.EVENT_2:
  252. break;
  253. default:
  254. break;
  255. }
  256. }
  257. private void OnDestroy()
  258. {
  259. //EventManager.Instance.Remove(this);
  260. }
  261. }