ArtEditorContainer.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. try
  84. {
  85. Cleartime();
  86. if (artContainer != null)
  87. {
  88. if (ItemFileList.Instance)
  89. {
  90. ItemFileList.Instance.DeleteFileIcon(this.artContainer);
  91. HttpsSendLog.Instance.SendLog("ClickOnDelete", " DeleteFileIcon " + ItemFileList.Instance.ToString() + " this.artContainer " + this.artContainer.GetGoodsInfo().goods_name);
  92. gameObject.SetActive(false);
  93. this.artContainer.GetInstace().gameObject.SetActive(false);
  94. }
  95. else
  96. {
  97. HttpsSendLog.Instance.SendLog("ClickOnDelete", " this.artContainer " + this.artContainer.GetGoodsInfo().goods_name);
  98. gameObject.SetActive(false);
  99. this.artContainer.DestroyArt();
  100. }
  101. }
  102. }
  103. catch (Exception e)
  104. {
  105. HttpsSendLog.Instance.SendLog("ClickOnDelete", e.Message);
  106. }
  107. }
  108. private void ClickOnCopy()
  109. {
  110. Cleartime();
  111. if (artContainer != null)
  112. {
  113. artContainer.CloneContainer();
  114. }
  115. }
  116. private void ClickOnNextStep()
  117. {
  118. Cleartime();
  119. if (artContainer != null)
  120. {
  121. if (artContainer.AheadCount() > 0)
  122. {
  123. artContainer.GoAhead();
  124. }
  125. RefreshUI();
  126. }
  127. }
  128. private void ClickOnLastStep()
  129. {
  130. Cleartime();
  131. if (artContainer != null)
  132. {
  133. if (artContainer.BackCount() > 0)
  134. {
  135. artContainer.GoBack();
  136. }
  137. RefreshUI();
  138. }
  139. }
  140. public void SetTarget(ArtContainer art, bool isDel)
  141. {
  142. Init();
  143. nameText.text = art.GetGoodsInfo().goods_name;
  144. if (isDel)
  145. {
  146. try
  147. {
  148. if (this.artContainer != null && artContainer.Transfer)
  149. {
  150. artContainer.Transfer.TransferStateChange -= OnTransferStateChange;
  151. artContainer.Transfer.TransferDisEnable -= OnTransferDisEnable;
  152. }
  153. }
  154. catch
  155. {
  156. UnityLog.Instance.LogError("菜单编辑器错误");
  157. }
  158. this.artContainer = null;
  159. gameObject.SetActive(false);
  160. return;
  161. }
  162. this.artContainer = art;
  163. if (art.Transfer)
  164. {
  165. art.Transfer.TransferStateChange += OnTransferStateChange;
  166. artContainer.Transfer.TransferDisEnable += OnTransferDisEnable;
  167. }
  168. var container = art.GetEditorCenter();
  169. if (container)
  170. {
  171. transform.position = container.position;
  172. transform.rotation = container.rotation;
  173. RefreshUI();
  174. }
  175. ReFresh();
  176. }
  177. private void OnTransferDisEnable()
  178. {
  179. gameObject.SetActive(false);
  180. if (artContainer != null && artContainer.Transfer)
  181. {
  182. artContainer.Transfer.TransferDisEnable -= OnTransferDisEnable;
  183. }
  184. }
  185. public void ReFresh()
  186. {
  187. if (artContainer != null && artContainer.Transfer)
  188. {
  189. if (artContainer.Transfer.IsJiXingScale)
  190. {
  191. editToggleBtn.isOn = true;
  192. editToggleBtn.image.sprite = editToggleBtn.openImg;
  193. }
  194. else
  195. {
  196. editToggleBtn.isOn = false;
  197. editToggleBtn.image.sprite = editToggleBtn.closeImg;
  198. }
  199. }
  200. }
  201. private void OnTransferStateChange(TransferState state)
  202. {
  203. try
  204. {
  205. if (artContainer != null && artContainer.GetInstace())
  206. {
  207. if (state == TransferState.Stop)
  208. {
  209. lastTime = 0;
  210. if (!gameObject.activeSelf)
  211. {
  212. gameObject.SetActive(true);
  213. }
  214. RefreshUI();
  215. }
  216. else
  217. {
  218. gameObject.SetActive(false);
  219. }
  220. }
  221. }
  222. catch
  223. {
  224. gameObject.SetActive(false);
  225. }
  226. }
  227. /// <summary>
  228. /// 编辑同步和
  229. /// </summary>
  230. private void Update()
  231. {
  232. if (artContainer != null)
  233. {
  234. try
  235. {
  236. if (!artContainer.GetInstace())
  237. {
  238. artContainer = null;
  239. return;
  240. }
  241. }
  242. catch
  243. {
  244. artContainer = null;
  245. return;
  246. }
  247. if (Input.GetKeyDown(KeyCode.Space))
  248. {
  249. UnityLog.Instance.Log("Back:" + artContainer.BackCount() + " Ahead:" + artContainer.AheadCount());
  250. artContainer.CloneContainer();
  251. }
  252. //if (Time.time - lastTime > checkTime)
  253. //{
  254. // lastTime = Time.time;
  255. // artContainer.ResetEditorPosition();
  256. // var container = artContainer.GetEditorCenter();
  257. // if (container)
  258. // {
  259. // transform.position = container.position;
  260. // transform.rotation = container.rotation;
  261. // }
  262. //}
  263. }
  264. }
  265. private void RefreshUI()
  266. {
  267. if (artContainer.BackCount() <= 0)
  268. {
  269. lastStepBtn.enabled = false;
  270. lastIcon.color = Color.gray;
  271. }
  272. else
  273. {
  274. lastStepBtn.enabled = true;
  275. lastIcon.color = Color.white;
  276. }
  277. if (artContainer.AheadCount() <= 0)
  278. {
  279. nextStepBtn.enabled = false;
  280. nextIcon.color = Color.gray;
  281. }
  282. else
  283. {
  284. nextStepBtn.enabled = true;
  285. nextIcon.color = Color.white;
  286. }
  287. }
  288. private void Cleartime()
  289. {
  290. if (artContainer != null)
  291. {
  292. artContainer.Transfer.ClearTime();
  293. }
  294. }
  295. }
  296. }