ArtEditorContainer.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. using SC.XR.Unity;
  2. using ShadowStudio.Tool;
  3. using ShadowStudio.UI;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Dynamic;
  8. using System.Text.RegularExpressions;
  9. using UnityEngine;
  10. using UnityEngine.UI;
  11. using XRTool.UI;
  12. using XRTool.Util;
  13. using XRTool.WorldUI;
  14. namespace ShadowStudio.Model
  15. {
  16. /// <summary>
  17. /// 资源的编辑
  18. /// </summary>
  19. [RequireComponent(typeof(WorldDlg))]
  20. public class ArtEditorContainer : UnitySingleton<ArtEditorContainer>
  21. {
  22. private ArtContainer artContainer;
  23. private Button lastStepBtn;
  24. private Button nextStepBtn;
  25. private ToggleButton editToggleBtn;
  26. private Button copyBtn;
  27. private Button deleteBtn;
  28. private WorldDlg dlg;
  29. private XRIcon lastIcon;
  30. private XRIcon nextIcon;
  31. public float checkTime = 1;
  32. private float lastTime;
  33. private Text nameText;
  34. private void Init()
  35. {
  36. if (dlg == null)
  37. {
  38. dlg = GetComponent<WorldDlg>();
  39. lastStepBtn = dlg.GetBreadthChild<Button>("LastStepBtn");
  40. nextStepBtn = dlg.GetBreadthChild<Button>("NextStepBtn");
  41. editToggleBtn = dlg.GetBreadthChild<ToggleButton>("EditToggleBtn");
  42. copyBtn = dlg.GetBreadthChild<Button>("CopyBtn");
  43. deleteBtn = dlg.GetBreadthChild<Button>("DeleteBtn");
  44. lastIcon = dlg.GetBreadthChild<XRIcon>("LastIcon");
  45. nextIcon = dlg.GetBreadthChild<XRIcon>("NextIcon");
  46. nameText = dlg.GetBreadthChild<Text>("NameText");
  47. lastStepBtn.onClick.AddListener(ClickOnLastStep);
  48. nextStepBtn.onClick.AddListener(ClickOnNextStep);
  49. copyBtn.onClick.AddListener(ClickOnCopy);
  50. deleteBtn.onClick.AddListener(ClickOnDelete);
  51. editToggleBtn.OnValueChanged += OnClickEditValueChange;
  52. }
  53. }
  54. private void OnClickEditValueChange(bool ison)
  55. {
  56. Cleartime();
  57. if (artContainer != null)
  58. {
  59. if (ison)
  60. {
  61. artContainer.Transfer.IsJiXingScale = true;
  62. if (ToggleShowBtnTip.Instance)
  63. {
  64. ToggleShowBtnTip.Instance.BtnTiptext.text = "拉伸";
  65. }
  66. }
  67. else
  68. {
  69. artContainer.Transfer.IsJiXingScale = false;
  70. if (ToggleShowBtnTip.Instance)
  71. {
  72. ToggleShowBtnTip.Instance.BtnTiptext.text = "缩放";
  73. }
  74. }
  75. if (ArtMoreEditor.Instance)
  76. {
  77. ArtMoreEditor.Instance.ReFresh();
  78. }
  79. }
  80. }
  81. private void ClickOnDelete()
  82. {
  83. Cleartime();
  84. if (artContainer != null)
  85. {
  86. if (ItemFileList.Instance)
  87. {
  88. ItemFileList.Instance.DeleteFileIcon(this.artContainer);
  89. }
  90. else
  91. {
  92. this.artContainer.DestroyArt();
  93. gameObject.SetActive(false);
  94. }
  95. }
  96. }
  97. private void ClickOnCopy()
  98. {
  99. Cleartime();
  100. if (artContainer != null)
  101. {
  102. artContainer.CloneContainer();
  103. }
  104. }
  105. private void ClickOnNextStep()
  106. {
  107. Cleartime();
  108. if (artContainer != null)
  109. {
  110. if (artContainer.AheadCount() > 0)
  111. {
  112. artContainer.GoAhead();
  113. }
  114. RefreshUI();
  115. }
  116. }
  117. private void ClickOnLastStep()
  118. {
  119. Cleartime();
  120. if (artContainer != null)
  121. {
  122. if (artContainer.BackCount() > 0)
  123. {
  124. artContainer.GoBack();
  125. }
  126. RefreshUI();
  127. }
  128. }
  129. public void SetTarget(ArtContainer art, bool isDel)
  130. {
  131. Init();
  132. nameText.text = art.GetGoodsInfo().goods_name;
  133. if (isDel)
  134. {
  135. try
  136. {
  137. if (this.artContainer != null && artContainer.Transfer)
  138. {
  139. artContainer.Transfer.TransferStateChange -= OnTransferStateChange;
  140. artContainer.Transfer.TransferDisEnable -= OnTransferDisEnable;
  141. }
  142. }
  143. catch
  144. {
  145. UnityLog.Instance.LogError("菜单编辑器错误");
  146. }
  147. this.artContainer = null;
  148. gameObject.SetActive(false);
  149. return;
  150. }
  151. this.artContainer = art;
  152. if (art.Transfer)
  153. {
  154. art.Transfer.TransferStateChange += OnTransferStateChange;
  155. artContainer.Transfer.TransferDisEnable += OnTransferDisEnable;
  156. }
  157. var container = art.GetEditorCenter();
  158. if (container)
  159. {
  160. transform.position = container.position;
  161. transform.rotation = container.rotation;
  162. RefreshUI();
  163. }
  164. ReFresh();
  165. }
  166. private void OnTransferDisEnable()
  167. {
  168. gameObject.SetActive(false);
  169. if (artContainer != null && artContainer.Transfer)
  170. {
  171. artContainer.Transfer.TransferDisEnable -= OnTransferDisEnable;
  172. }
  173. }
  174. public void ReFresh()
  175. {
  176. if (artContainer != null && artContainer.Transfer)
  177. {
  178. if (artContainer.Transfer.IsJiXingScale)
  179. {
  180. editToggleBtn.isOn = true;
  181. editToggleBtn.image.sprite = editToggleBtn.openImg;
  182. }
  183. else
  184. {
  185. editToggleBtn.isOn = false;
  186. editToggleBtn.image.sprite = editToggleBtn.closeImg;
  187. }
  188. }
  189. }
  190. private void OnTransferStateChange(TransferState state)
  191. {
  192. try
  193. {
  194. if (artContainer != null && artContainer.GetInstace())
  195. {
  196. if (state == TransferState.Stop)
  197. {
  198. lastTime = 0;
  199. if (!gameObject.activeSelf)
  200. {
  201. gameObject.SetActive(true);
  202. }
  203. RefreshUI();
  204. }
  205. else
  206. {
  207. gameObject.SetActive(false);
  208. }
  209. }
  210. }
  211. catch
  212. {
  213. gameObject.SetActive(false);
  214. }
  215. }
  216. /// <summary>
  217. /// 编辑同步和
  218. /// </summary>
  219. private void Update()
  220. {
  221. if (artContainer != null)
  222. {
  223. try
  224. {
  225. if (!artContainer.GetInstace())
  226. {
  227. artContainer = null;
  228. return;
  229. }
  230. }
  231. catch
  232. {
  233. artContainer = null;
  234. return;
  235. }
  236. if (Input.GetKeyDown(KeyCode.Space))
  237. {
  238. UnityLog.Instance.Log("Back:" + artContainer.BackCount() + " Ahead:" + artContainer.AheadCount());
  239. artContainer.CloneContainer();
  240. }
  241. //if (Time.time - lastTime > checkTime)
  242. //{
  243. // lastTime = Time.time;
  244. // artContainer.ResetEditorPosition();
  245. // var container = artContainer.GetEditorCenter();
  246. // if (container)
  247. // {
  248. // transform.position = container.position;
  249. // transform.rotation = container.rotation;
  250. // }
  251. //}
  252. }
  253. }
  254. private void RefreshUI()
  255. {
  256. if (artContainer.BackCount() <= 0)
  257. {
  258. lastStepBtn.enabled = false;
  259. lastIcon.color = Color.gray;
  260. }
  261. else
  262. {
  263. lastStepBtn.enabled = true;
  264. lastIcon.color = Color.white;
  265. }
  266. if (artContainer.AheadCount() <= 0)
  267. {
  268. nextStepBtn.enabled = false;
  269. nextIcon.color = Color.gray;
  270. }
  271. else
  272. {
  273. nextStepBtn.enabled = true;
  274. nextIcon.color = Color.white;
  275. }
  276. }
  277. private void Cleartime()
  278. {
  279. if (artContainer != null)
  280. {
  281. artContainer.Transfer.ClearTime();
  282. }
  283. }
  284. }
  285. }