LabelUtility.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. using System.Reflection;
  2. namespace labelUtility
  3. {
  4. #if UNITY_EDITOR
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using System.Xml;
  13. using UnityEditor;
  14. using UnityEngine;
  15. using UnityEngine.UI;
  16. [Serializable]
  17. public class RegistTarget
  18. {
  19. public string Name;
  20. public bool Force;
  21. public bool Ignore;
  22. //public bool CustomName;
  23. public bool CustomEvent = true;
  24. public Transform Transform;
  25. public ComponentType Type;
  26. }
  27. [Serializable]
  28. public class ComponentEventString
  29. {
  30. public ComponentType ComponentType;
  31. public List<string> RegistStrings;
  32. public List<string> MethodNames;
  33. }
  34. [Serializable]
  35. public class LabelSet
  36. {
  37. public string Name;
  38. public UtilityType UtilityType;
  39. public string LabelScriptPath;
  40. public string LabelScriptName;
  41. public string LabePrefix = "public static string";
  42. public TextAsset LabelScript;
  43. public string ComponentScriptPath;
  44. public string ComponentScriptName;
  45. public string DerivedString;
  46. public string RegistMethodString;
  47. public string ComponentPrefix = "private";
  48. public string NameExcludeString;
  49. public string RegistString;
  50. public List<string> RegistExtraLines;
  51. public TextAsset ComponentScript;
  52. public List<TextAsset> Languages;
  53. public List<GameObject> Prefabs;
  54. public bool FoldOut;
  55. public float TotalHeight;
  56. public List<ComponentType> RegistTypes = new List<ComponentType>();
  57. public List<RegistTarget> RegistTargets = new List<RegistTarget>();
  58. }
  59. [Serializable]
  60. public enum ComponentType
  61. {
  62. None,
  63. Text,
  64. Slider,
  65. Image,
  66. Button,
  67. InputField,
  68. Transform,
  69. CanvasGroup,
  70. RectTransform,
  71. SpriteRenderer,
  72. VirtualScrollRectPlus,
  73. }
  74. public enum UtilityType
  75. {
  76. XmlLabel,
  77. PrefabLabel,
  78. Regist,
  79. }
  80. public class LabelUtility : MonoBehaviour
  81. {
  82. #region Config
  83. public List<string> DllNames;
  84. public List<ComponentEventString> EventStrings;
  85. public List<LabelSet> LabelSets;
  86. public static string StartMark = "//StartMark-Used by LabelUtility-Do not remove";
  87. public static string EndMark = "//EndMark-Used by LabelUtility-Do not remove";
  88. public static string RegistStartMark = "//RegistStartMark-Used by LabelUtility-Do not remove";
  89. public static string RegistEndMark = "//RegistEndMark-Used by LabelUtility-Do not remove";
  90. public static string EventStartMark = "//EventStartMark-Used by LabelUtility-Do not remove";
  91. public static string EventEndMark = "//EventEndMark-Used by LabelUtility-Do not remove";
  92. public static string RegistEventStartMark = "//RegistEventStartMark-Used by LabelUtility-Do not remove";
  93. public static string RegistEventEndMark = "//RegistEventEndMark-Used by LabelUtility-Do not remove";
  94. public static string Prefix = "public static string ";
  95. #endregion
  96. public static void CreateLabelScript(LabelSet labelSet, bool showWarning = true, bool auto = false)
  97. {
  98. if (showWarning)
  99. {
  100. if (!EditorUtility.DisplayDialog("注意", "新建LabelScript?", "确定", "取消"))
  101. {
  102. return;
  103. }
  104. }
  105. if (!auto)
  106. {
  107. auto = EditorUtility.DisplayDialog("提示", "是否自动提取标签", "确定", "取消");
  108. }
  109. string scriptContent = "";
  110. foreach (var dllName in InstanceManager.SearchInstance<LabelUtility>().DllNames)
  111. {
  112. scriptContent += $"using {dllName};\r\n";
  113. }
  114. scriptContent += "\r\n";
  115. scriptContent += $"public class {labelSet.LabelScriptName}";
  116. scriptContent += "\r\n";
  117. scriptContent += $"{{\r\n\t#region Config\r\n\r\n\t{StartMark}\r\n\t{EndMark}\r\n\r\n\t#endregion\r\n}}";
  118. labelSet.LabelScript = CreateScript(labelSet.LabelScriptName, labelSet.LabelScriptPath, scriptContent);
  119. if (auto)
  120. {
  121. if (labelSet.UtilityType == UtilityType.XmlLabel)
  122. {
  123. CreateLabelFromLanguageXml(labelSet, false);
  124. }
  125. else if (labelSet.UtilityType == UtilityType.Regist || labelSet.UtilityType == UtilityType.PrefabLabel)
  126. {
  127. CreateLabelFromPrefab(labelSet, false);
  128. }
  129. }
  130. }
  131. public static void CreateComponentScript(LabelSet labelSet, bool showWarning = true, bool regist = false)
  132. {
  133. if (showWarning)
  134. {
  135. if (!EditorUtility.DisplayDialog("注意", "新建ComponentScript?", "确定", "取消"))
  136. {
  137. return;
  138. }
  139. }
  140. if (!regist)
  141. {
  142. regist = EditorUtility.DisplayDialog("提示", "是否自动注册", "确定", "取消");
  143. }
  144. string scriptContent = "";
  145. foreach (var dllName in InstanceManager.SearchInstance<LabelUtility>().DllNames)
  146. {
  147. scriptContent += $"using {dllName};\r\n";
  148. }
  149. scriptContent += "\r\n";
  150. scriptContent += $"public class {labelSet.ComponentScriptName}";
  151. if (string.IsNullOrEmpty(labelSet.DerivedString))
  152. {
  153. scriptContent += "\r\n";
  154. }
  155. else
  156. {
  157. scriptContent += $" : {labelSet.DerivedString}\r\n";
  158. }
  159. scriptContent += $"{{\r\n\t#region Config\r\n\r\n\t{StartMark}\r\n\t{EndMark}\r\n\r\n\t#endregion\r\n";
  160. scriptContent += "\r\n";
  161. if (!string.IsNullOrEmpty(labelSet.RegistMethodString))
  162. {
  163. scriptContent += $"\t{labelSet.RegistMethodString}\r\n\t{{\r\n";
  164. scriptContent += $"\t\t{RegistStartMark}\r\n";
  165. scriptContent += $"\t\t{RegistEndMark}\r\n";
  166. scriptContent += $"\t\t{RegistEventStartMark}\r\n";
  167. scriptContent += $"\t\t{RegistEventEndMark}\r\n";
  168. scriptContent += $"\t}}\r\n";
  169. }
  170. scriptContent += "\r\n";
  171. scriptContent += $"\t{EventStartMark}\r\n";
  172. scriptContent += $"\t{EventEndMark}\r\n";
  173. scriptContent += $"}}";
  174. labelSet.ComponentScript = CreateScript(labelSet.ComponentScriptName, labelSet.ComponentScriptPath, scriptContent);
  175. if (regist)
  176. {
  177. CreateComponentsFromPrefab(labelSet, false);
  178. }
  179. }
  180. private static TextAsset CreateScript(string scriptName, string scriptPath, string content)
  181. {
  182. string directory = scriptPath.TrimEnd('/', '\\') + "/";
  183. if (directory.Length < 6 || directory.Substring(0, 6).ToLower() != "assets")
  184. {
  185. throw new Exception("ScripPath必须位置Assets目录内");
  186. }
  187. if (!Directory.Exists(directory))
  188. {
  189. throw new Exception("文件夹不存在");
  190. }
  191. if (string.IsNullOrEmpty(scriptName) || scriptName.Any(Path.GetInvalidFileNameChars().Contains))
  192. {
  193. throw new Exception("ScripName包含无效字符");
  194. }
  195. string fullPath = $"{scriptPath}/{scriptName}.cs";
  196. if (File.Exists(fullPath))
  197. {
  198. throw new Exception($"已经存在一个 {fullPath}");
  199. }
  200. File.WriteAllText(fullPath, content);
  201. AssetDatabase.Refresh();
  202. return AssetDatabase.LoadAssetAtPath<TextAsset>(fullPath);
  203. }
  204. public static void CreateLabelFromPrefab(LabelSet labelSet, bool showWarning = true, bool regist = false)
  205. {
  206. if (labelSet.LabelScript == null)
  207. {
  208. Debug.LogError("LabelScript is null");
  209. return;
  210. }
  211. if (showWarning)
  212. {
  213. if (!EditorUtility.DisplayDialog("注意", "重新生成Prefab Label?", "确定", "取消"))
  214. {
  215. return;
  216. }
  217. }
  218. if (!regist)
  219. {
  220. regist = EditorUtility.DisplayDialog("提示", "是否自动注册", "确定", "取消");
  221. }
  222. List<string> labels = new List<string>();
  223. List<Transform> transforms = GetAllTransformFromPrefab(labelSet.Prefabs);
  224. foreach (var transform in transforms)
  225. {
  226. labels.Add($"{labelSet.LabePrefix} {transform.name} = \"{transform.name}\";");
  227. }
  228. InsertLineToScript(StartMark, EndMark, labelSet.LabelScript, labels);
  229. if (regist)
  230. {
  231. CreateComponentsFromPrefab(labelSet, false);
  232. }
  233. }
  234. public static void CreateLabelFromLanguageXml(LabelSet labelSet, bool showWarning = true)
  235. {
  236. if (labelSet.LabelScript == null)
  237. {
  238. Debug.LogError("LabelScript is null");
  239. return;
  240. }
  241. if (showWarning)
  242. {
  243. if (!EditorUtility.DisplayDialog("注意", "重新生成LanguageXml Label?", "确定", "取消"))
  244. {
  245. return;
  246. }
  247. }
  248. List<string> labels = new List<string>();
  249. foreach (var language in labelSet.Languages)
  250. {
  251. XmlDocument document = new XmlDocument();
  252. document.LoadXml(language.text);
  253. XmlNodeList childNodes = document.SelectSingleNode("lan").ChildNodes;
  254. for (int i = 0; i < childNodes.Count; i++)
  255. {
  256. labels.AddRange(GetAllLabelFromXmlNode(childNodes[i], labelSet));
  257. }
  258. }
  259. InsertLineToScript(StartMark, EndMark, labelSet.LabelScript, labels);
  260. }
  261. private static List<string> GetAllLabelFromXmlNode(XmlNode node, LabelSet labelSet)
  262. {
  263. List<string> labels = new List<string>();
  264. for (int i = 0; i < node.ChildNodes.Count; i++)
  265. {
  266. XmlNode childNode = node.ChildNodes[i];
  267. string label;
  268. if (i == 0)
  269. {
  270. label = $"\t{labelSet.LabePrefix} {node.Name} = \"{node.Name}\";";
  271. labels.Add(label);
  272. }
  273. label = $"\t{labelSet.LabePrefix} {node.Name}{LanguageLabel.LanguagePageSeperator}{childNode.Name} = \"{node.Name}{LanguageLabel.LanguagePageSeperator}{childNode.Name}\";";
  274. labels.Add(label);
  275. }
  276. return labels;
  277. }
  278. public static Type GetType(ComponentType componentType)
  279. {
  280. Assembly assembly = Assembly.Load("UnityEngine.UI");
  281. Type type = assembly.GetType($"UnityEngine.UI.{componentType}");
  282. if (type == null)
  283. {
  284. assembly = Assembly.Load("UnityEngine");
  285. type = assembly.GetType($"UnityEngine.{componentType}");
  286. }
  287. if (type == null)
  288. {
  289. assembly = Assembly.Load("Assembly-CSharp");
  290. type = assembly.GetType($"{componentType}");
  291. }
  292. return type;
  293. }
  294. public static void CreateComponentsFromPrefab(LabelSet labelSet, bool showWarning = true)
  295. {
  296. if (labelSet.ComponentScript == null)
  297. {
  298. Debug.LogError("ComponentScript is null");
  299. return;
  300. }
  301. if (showWarning)
  302. {
  303. if (!EditorUtility.DisplayDialog("注意", "重新生成PrefabComponent?", "确定", "取消"))
  304. {
  305. return;
  306. }
  307. }
  308. List<string> defineStrings = new List<string>();
  309. List<string> registStrings = new List<string>();
  310. List<string> eventNames = new List<string>();
  311. List<string> registEventStrings = new List<string>();
  312. registStrings.AddRange(labelSet.RegistExtraLines);
  313. foreach (var registTarget in labelSet.RegistTargets)
  314. {
  315. if (registTarget.Ignore) continue;
  316. defineStrings.Add($"{labelSet.ComponentPrefix} {registTarget.Type} {registTarget.Transform.name};");
  317. string registString = labelSet.RegistString.Replace("#NAME", registTarget.Transform.name).Replace("#TYPE", registTarget.Type.ToString()).Replace("#NEWNAME", registTarget.Name);
  318. if (labelSet.LabelScript != null)
  319. {
  320. registString = registString.Replace("#LABEL", labelSet.LabelScript.name);
  321. }
  322. registStrings.Add(registString);
  323. foreach (var eventString in InstanceManager.SearchInstance<LabelUtility>().EventStrings)
  324. {
  325. if (eventString.ComponentType == registTarget.Type)
  326. {
  327. if (!registTarget.CustomEvent)
  328. {
  329. continue;
  330. }
  331. for (int i = 0; i < eventString.MethodNames.Count; i++)
  332. {
  333. eventNames.Add($"{eventString.MethodNames[i].Replace("#NEWNAME", registTarget.Name).Replace("#NAME", registTarget.Transform.name)}");
  334. }
  335. for (int i = 0; i < eventString.RegistStrings.Count; i++)
  336. {
  337. registEventStrings.Add($"{eventString.RegistStrings[i].Replace("#NEWNAME", registTarget.Name).Replace("#NAME", registTarget.Transform.name)};");
  338. }
  339. }
  340. }
  341. }
  342. //foreach (var eventString in eventStrings)
  343. //{
  344. // Debug.Log(eventString);
  345. //}
  346. int? startIndex = null;
  347. int? endIndex = null;
  348. List<string> oldEventMethods = GetScriptContentBetweenMarks(EventStartMark, EventEndMark, labelSet.ComponentScript, ref startIndex, ref endIndex);
  349. List<string> newEventMethods = new List<string>();
  350. int? tabAmount = GetMarkSpaceAmount(labelSet.ComponentScript, EventStartMark);
  351. for (int i = 0; i < eventNames.Count; i++)
  352. {
  353. List<string> methodStrings = TryGetMethodStrings(eventNames[i], oldEventMethods);
  354. if (methodStrings.Valid())
  355. {
  356. for (int j = 0; j < methodStrings.Count; j++)
  357. {
  358. if (tabAmount == null)
  359. {
  360. newEventMethods.Add(methodStrings[j]);
  361. }
  362. else
  363. {
  364. //Debug.Log((int)methodStrings[j][0]);
  365. //Debug.Log((int)methodStrings[j][1]);
  366. //Debug.LogWarning(methodStrings[j]);
  367. //Debug.Log(methodStrings[j].Length);
  368. string str = methodStrings[j].Length > 0 ? methodStrings[j].Substring(tabAmount.Value) : methodStrings[j];
  369. newEventMethods.Add(str);
  370. }
  371. }
  372. if (i < eventNames.Count - 1)
  373. {
  374. newEventMethods.Add("");
  375. }
  376. }
  377. else
  378. {
  379. newEventMethods.Add($"{labelSet.ComponentPrefix} {eventNames[i]}");
  380. newEventMethods.Add("{\r\n");
  381. newEventMethods.Add(i < eventNames.Count - 1 ? "}\r\n" : "}");
  382. }
  383. }
  384. InsertLineToScript(StartMark, EndMark, labelSet.ComponentScript, defineStrings);
  385. InsertLineToScript(RegistStartMark, RegistEndMark, labelSet.ComponentScript, registStrings);
  386. InsertLineToScript(RegistEventStartMark, RegistEventEndMark, labelSet.ComponentScript, registEventStrings);
  387. InsertLineToScript(EventStartMark, EventEndMark, labelSet.ComponentScript, newEventMethods);
  388. //foreach (var registEventString in registEventStrings)
  389. //{
  390. // Debug.Log(registEventString);
  391. //}
  392. //List <string> typeNames = new List<string>();
  393. //foreach (var purview in labelSet.RegistTypes)
  394. //{
  395. // typeNames.Add(purview.ToString());
  396. //}
  397. //List <Transform> transforms = GetAllTransformFromPrefab(labelSet.Prefabs);
  398. //Dictionary<string, List<string>> namesDictionary = new Dictionary<string, List<string>>();
  399. //foreach (var name in typeNames)
  400. //{
  401. // namesDictionary.Add(name, new List<string>());
  402. //}
  403. //foreach (var kv in namesDictionary)
  404. //{
  405. // Assembly assembly = Assembly.Load("UnityEngine.UI");
  406. // Type type = assembly.GetType($"UnityEngine.UI.{kv.Key}");
  407. // if (type == null)
  408. // {
  409. // assembly = Assembly.Load("UnityEngine");
  410. // type = assembly.GetType($"UnityEngine.{kv.Key}");
  411. // }
  412. // if (type == null)
  413. // {
  414. // assembly = Assembly.Load("Assembly-CSharp");
  415. // type = assembly.GetType($"{kv.Key}");
  416. // }
  417. // foreach (var transform in transforms)
  418. // {
  419. // if (transform.GetComponent(type) == null) continue;
  420. // namesDictionary[kv.Key].Add(transform.name);
  421. // }
  422. //}
  423. //List<string> names = new List<string>();
  424. //List<string> components = new List<string>();
  425. //List<string> registStrings = new List<string>();
  426. //registStrings.AddRange(labelSet.RegistExtraLines);
  427. //foreach (var kv in namesDictionary)
  428. //{
  429. // foreach (var name in kv.Value)
  430. // {
  431. // names.Add(name);
  432. // string newName = string.IsNullOrEmpty(labelSet.NameExcludeString) ? name : name.Replace(labelSet.NameExcludeString, "");
  433. // components.Add($"{labelSet.ComponentPrefix} {kv.Key} {newName};");
  434. // string registString = labelSet.RegistString.Replace("#NAME", name).Replace("#TYPE", kv.Key).Replace("#NEWNAME", newName);
  435. // if (labelSet.LabelScript != null)
  436. // {
  437. // registString = registString.Replace("#LABEL", labelSet.LabelScript.name);
  438. // }
  439. // registStrings.Add(registString);
  440. // }
  441. //}
  442. //InsertLineToScript(StartMark, EndMark, labelSet.ComponentScript, components);
  443. //InsertLineToScript(RegistStartMark, RegistEndMark, labelSet.ComponentScript, registStrings);
  444. }
  445. private static List<string> TryGetMethodStrings(string methodName, List<string> strings)
  446. {
  447. List<string> results = new List<string>();
  448. for (int i = 0; i < strings.Count; i++)
  449. {
  450. if (!strings[i].Contains(methodName)) continue;
  451. for (int j = i; j < strings.Count; j++)
  452. {
  453. results.Add(strings[j]);
  454. if (strings[j].Trim() == "}")
  455. {
  456. return results;
  457. }
  458. }
  459. }
  460. return results;
  461. }
  462. private static void InsertLineToScript(int startIndex, TextAsset textAsset, List<string> insertLines)
  463. {
  464. List<string> strings = GetScriptContents(textAsset);
  465. int prefixIndex = strings[startIndex].IndexOf("//");
  466. string prefix = strings[startIndex].Substring(0, prefixIndex);
  467. for (int i = 0; i < insertLines.Count; i++)
  468. {
  469. strings.Insert(startIndex, prefix + insertLines[i]);
  470. startIndex++;
  471. }
  472. StringBuilder stringBuilder = new StringBuilder();
  473. for (int i = 0; i < strings.Count; i++)
  474. {
  475. stringBuilder.AppendLine(strings[i]);
  476. }
  477. string content = stringBuilder.ToString();
  478. content = content.Substring(0, content.Length - 2);
  479. File.WriteAllText(AssetDatabase.GetAssetPath(textAsset), content);
  480. AssetDatabase.Refresh();
  481. }
  482. private static void InsertLineToScript(string startMark, string endMark, TextAsset textAsset, List<string> insertLines)
  483. {
  484. int? startMarkLineIndex = null;
  485. int? endMarkLineIndex = null;
  486. List<string> strings = GetScriptContentAfterClearMarks(startMark, endMark, textAsset, ref startMarkLineIndex, ref endMarkLineIndex);
  487. int prefixIndex = strings[startMarkLineIndex.Value].IndexOf("//");
  488. string prefix = strings[startMarkLineIndex.Value].Substring(0, prefixIndex);
  489. for (int i = 0; i < insertLines.Count; i++)
  490. {
  491. strings.Insert(startMarkLineIndex.Value + 1, prefix + insertLines[i]);
  492. startMarkLineIndex++;
  493. }
  494. StringBuilder stringBuilder = new StringBuilder();
  495. for (int i = 0; i < strings.Count; i++)
  496. {
  497. stringBuilder.AppendLine(strings[i]);
  498. }
  499. string content = stringBuilder.ToString();
  500. content = content.Substring(0, content.Length - 2);
  501. File.WriteAllText(AssetDatabase.GetAssetPath(textAsset), content);
  502. AssetDatabase.Refresh();
  503. }
  504. private static int? GetMarkIndex(TextAsset textAsset, string mark)
  505. {
  506. List<string> strings = textAsset.text.Split(new[] { "\r\n" }, StringSplitOptions.None).ToList();
  507. for (int i = 0; i < strings.Count; i++)
  508. {
  509. if (strings[i].Contains(mark))
  510. {
  511. return i;
  512. }
  513. }
  514. return null;
  515. }
  516. private static int? GetMarkSpaceAmount(TextAsset textAsset, string mark)
  517. {
  518. List<string> strings = textAsset.text.Split(new[] { "\r\n" }, StringSplitOptions.None).ToList();
  519. for (int i = 0; i < strings.Count; i++)
  520. {
  521. if (strings[i].Contains(mark))
  522. {
  523. if (Regex.Match(strings[i], "^\\s+").Success)
  524. {
  525. //Debug.Log(Regex.Match(strings[i], "^\\s+").Length);
  526. return Regex.Match(strings[i], "^\\s+").Length;
  527. }
  528. else
  529. {
  530. return null;
  531. }
  532. }
  533. }
  534. return null;
  535. }
  536. private static List<string> GetScriptContentBetweenMarks(string startMark, string endMark, TextAsset textAsset, ref int? startMarkLineIndex, ref int? endMarkLineIndex)
  537. {
  538. //Debug.Log(textAsset.text);
  539. List<string> strings = textAsset.text.Split(new[] { "\r\n" }, StringSplitOptions.None).ToList();
  540. for (int i = 0; i < strings.Count; i++)
  541. {
  542. if (strings[i].Contains(startMark))
  543. {
  544. //Debug.Log(strings[i][0]);
  545. //Debug.LogWarning(strings[i][1]);
  546. //Debug.Log(strings[i][2]);
  547. //Debug.LogWarning(strings[i][3]);
  548. //Debug.Log(strings[i][4]);
  549. //Debug.LogWarning(strings[i][5]);
  550. startMarkLineIndex = i;
  551. }
  552. else if (strings[i].Contains(endMark))
  553. {
  554. endMarkLineIndex = i;
  555. }
  556. }
  557. List<string> results = new List<string>();
  558. for (int i = startMarkLineIndex.Value + 1; i < endMarkLineIndex.Value; i++)
  559. {
  560. //if (strings[i].Length > 0)
  561. //{
  562. // Debug.Log(strings[i][0]);
  563. //}
  564. //if (strings[i].Length > 1)
  565. //{
  566. // Debug.LogWarning(strings[i][1]);
  567. //}
  568. results.Add(strings[i]);
  569. }
  570. return results;
  571. }
  572. private static List<string> GetScriptContents(TextAsset textAsset)
  573. {
  574. List<string> strings = textAsset.text.Split(new[] { "\r\n" }, StringSplitOptions.None).ToList();
  575. return strings;
  576. }
  577. private static List<string> GetScriptContentAfterClearMarks(string startMark, string endMark, TextAsset textAsset, ref int? startMarkLineIndex, ref int? endMarkLineIndex)
  578. {
  579. List<string> strings = textAsset.text.Split(new[] {"\r\n"}, StringSplitOptions.None).ToList();
  580. //List<string> currentDefinedNames = new List<string>();
  581. for (int i = 0; i < strings.Count; i++)
  582. {
  583. if (strings[i].Contains(startMark))
  584. {
  585. startMarkLineIndex = i;
  586. }
  587. else if (strings[i].Contains(endMark))
  588. {
  589. endMarkLineIndex = i;
  590. }
  591. //if (startMarkLineIndex != null)
  592. //{
  593. // if (endMarkLineIndex != null)
  594. // {
  595. // if (i > startMarkLineIndex.Value && i < endMarkLineIndex.Value)
  596. // {
  597. // currentDefinedNames.Add(GetDefinedName(strings[i]));
  598. // }
  599. // }
  600. // else
  601. // {
  602. // if (i > startMarkLineIndex.Value)
  603. // {
  604. // currentDefinedNames.Add(GetDefinedName(strings[i]));
  605. // }
  606. // }
  607. //}
  608. }
  609. int definedCount = endMarkLineIndex.Value - startMarkLineIndex.Value - 1;
  610. for (int i = 0; i < definedCount; i++)
  611. {
  612. strings.RemoveAt(startMarkLineIndex.Value + 1);
  613. }
  614. return strings;
  615. }
  616. private static List<Transform> GetAllTransformFromPrefab(List<GameObject> prefabs)
  617. {
  618. List<Transform> transforms = new List<Transform>();
  619. for (int i = 0; i < prefabs.Count; i++)
  620. {
  621. transforms.AddRange(prefabs[i].GetComponentsInChildren<Transform>(true));
  622. }
  623. return transforms;
  624. }
  625. }
  626. #endif
  627. }