FindTargetReference.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using UnityEditor;
  6. using UnityEngine;
  7. public class FindTargetReference : MonoBehaviour
  8. {
  9. private static string mTargetPrefab = "Resources/Prefabs/Targets";
  10. [MenuItem("Assets/查找靶子动画的使用情况")]
  11. public static void FindTargetAnimClip()
  12. {
  13. DataManager.Instance.InitData();
  14. AnimationClip selected = Selection.activeObject as AnimationClip;
  15. List<int> targetIDList = new List<int>();
  16. List<string> targetNameList = new List<string>();
  17. var targetDatas = DataManager.Instance.csvData.TargetData;
  18. for (int i = 0; i < targetDatas.Count; ++i)
  19. {
  20. if (targetDatas[i].Hit == selected.name || targetDatas[i].Death == selected.name || targetDatas[i].CtrlAniFileName == selected.name)
  21. {
  22. targetIDList.Add(targetDatas[i].ID);
  23. targetNameList.Add(targetDatas[i].ResourceName);
  24. }
  25. }
  26. //查询子靶子
  27. List<int> childTargetList = new List<int>();
  28. for (int i = 0; i < targetDatas.Count; ++i)
  29. {
  30. string child = targetDatas[i].Child;
  31. if (string.IsNullOrEmpty(child))
  32. {
  33. continue;
  34. }
  35. string[] childs = child.Split('#');
  36. int targetID = targetDatas[i].ID;
  37. foreach (string childID in childs)
  38. {
  39. int childTargetID = int.Parse(childID);
  40. for (int j = 0; j < targetIDList.Count; ++j)
  41. {
  42. if (childTargetID == targetIDList[j] && !childTargetList.Contains(targetID))
  43. {
  44. childTargetList.Add(targetID);
  45. }
  46. }
  47. }
  48. }
  49. //查询重生靶子
  50. List<int> reliveTargetList = new List<int>();
  51. for (int i = 0; i < targetDatas.Count; ++i)
  52. {
  53. int targetID = targetDatas[i].ID;
  54. int rID = targetDatas[i].ReID;
  55. for (int j = 0; j < targetIDList.Count; ++j)
  56. {
  57. if (rID == targetIDList[j] && !reliveTargetList.Contains(targetID))
  58. {
  59. reliveTargetList.Add(targetID);
  60. }
  61. }
  62. }
  63. List<int> levelList = new List<int>();
  64. var targetGroup = DataManager.Instance.csvData.TargetGroup;
  65. for (int i = 0; i < targetGroup.Count; ++i)
  66. {
  67. int targetID = targetGroup[i].TargetID;
  68. int levelID = targetGroup[i].GroupID;
  69. InsertLevelID(targetID, levelID, targetIDList, levelList);
  70. InsertLevelID(targetID, levelID, childTargetList, levelList);
  71. InsertLevelID(targetID, levelID, reliveTargetList, levelList);
  72. }
  73. levelList.Sort();
  74. Debug.Log(string.Format("动画[{0}] \n所属靶子名称:{1} \n所属靶子ID:{2} \n所属关卡ID:{3}", selected.name, List2String(targetNameList), List2String(targetIDList), List2String(levelList)));
  75. }
  76. [MenuItem("Assets/查找靶子的使用情况")]
  77. public static void FindWhereTarget()
  78. {
  79. DataManager.Instance.InitData();
  80. GameObject selected = Selection.activeObject as GameObject;
  81. FindTargetByName(selected.name);
  82. }
  83. private static void FindTargetByName(string targetName)
  84. {
  85. List<int> targetIDList = new List<int>();
  86. var targetDatas = DataManager.Instance.csvData.TargetData;
  87. for (int i = 0; i < targetDatas.Count; ++i)
  88. {
  89. if (targetDatas[i].ResourceName == targetName)
  90. {
  91. targetIDList.Add(targetDatas[i].ID);
  92. }
  93. }
  94. //查询子靶子
  95. List<int> childTargetList = new List<int>();
  96. for (int i = 0; i < targetDatas.Count; ++i)
  97. {
  98. string child = targetDatas[i].Child;
  99. if (string.IsNullOrEmpty(child))
  100. {
  101. continue;
  102. }
  103. string[] childs = child.Split('#');
  104. int targetID = targetDatas[i].ID;
  105. foreach (string childID in childs)
  106. {
  107. int childTargetID = int.Parse(childID);
  108. for (int j = 0; j < targetIDList.Count; ++j)
  109. {
  110. if (childTargetID == targetIDList[j] && !childTargetList.Contains(targetID))
  111. {
  112. childTargetList.Add(targetID);
  113. }
  114. }
  115. }
  116. }
  117. //查询重生靶子
  118. List<int> reliveTargetList = new List<int>();
  119. for (int i = 0; i < targetDatas.Count; ++i)
  120. {
  121. int targetID = targetDatas[i].ID;
  122. int rID = targetDatas[i].ReID;
  123. for (int j = 0; j < targetIDList.Count; ++j)
  124. {
  125. if (rID == targetIDList[j] && !reliveTargetList.Contains(targetID))
  126. {
  127. reliveTargetList.Add(targetID);
  128. }
  129. }
  130. }
  131. List<int> levelList = new List<int>();
  132. var targetGroup = DataManager.Instance.csvData.TargetGroup;
  133. for (int i = 0; i < targetGroup.Count; ++i)
  134. {
  135. int targetID = targetGroup[i].TargetID;
  136. int levelID = targetGroup[i].GroupID;
  137. InsertLevelID(targetID, levelID, targetIDList, levelList);
  138. InsertLevelID(targetID, levelID, childTargetList, levelList);
  139. InsertLevelID(targetID, levelID, reliveTargetList, levelList);
  140. }
  141. levelList.Sort();
  142. Debug.Log(string.Format("靶子[{0}]所属关卡:{1}", targetName, List2String(levelList)));
  143. }
  144. [MenuItem("NeoGame/所有靶子的使用情况")]
  145. public static void FindWhereTargetAll()
  146. {
  147. DataManager.Instance.InitData();
  148. string path = Path.Combine(Application.dataPath, mTargetPrefab);
  149. List<string> targetPrefabNames = new List<string>();
  150. if (Directory.Exists(path))
  151. {
  152. DirectoryInfo direction = new DirectoryInfo(path);
  153. FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
  154. for (int i = 0; i < files.Length; i++)
  155. {
  156. if (files[i].Name.EndsWith(".meta"))
  157. {
  158. continue;
  159. }
  160. string[] strName = files[i].Name.Split('.');
  161. string filename = strName[0];
  162. targetPrefabNames.Add(filename);
  163. }
  164. }
  165. for (int i = 0; i < targetPrefabNames.Count; ++i)
  166. {
  167. FindTargetByName(targetPrefabNames[i]);
  168. }
  169. Debug.Log("所有靶子查找完毕");
  170. }
  171. private static void InsertLevelID(int targetID, int levelID, List<int> data, List<int> result)
  172. {
  173. for (int i = 0; i < data.Count; ++i)
  174. {
  175. if (data[i] == targetID && !result.Contains(levelID))
  176. {
  177. result.Add(levelID);
  178. }
  179. }
  180. }
  181. private static string List2String<T>(List<T> list)
  182. {
  183. StringBuilder sb = new StringBuilder();
  184. for (int i = 0; i < list.Count; ++i)
  185. {
  186. sb.Append(list[i]);
  187. if (i != list.Count - 1)
  188. {
  189. sb.Append(",");
  190. }
  191. }
  192. string result = sb.ToString();
  193. if (string.IsNullOrEmpty(result))
  194. {
  195. sb.Append("无");
  196. }
  197. return sb.ToString();
  198. }
  199. }