123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using UnityEditor;
- using UnityEngine;
- public class FindTargetReference : MonoBehaviour
- {
- private static string mTargetPrefab = "Resources/Prefabs/Targets";
- [MenuItem("Assets/查找靶子动画的使用情况")]
- public static void FindTargetAnimClip()
- {
- DataManager.Instance.InitData();
- AnimationClip selected = Selection.activeObject as AnimationClip;
- List<int> targetIDList = new List<int>();
- List<string> targetNameList = new List<string>();
- var targetDatas = DataManager.Instance.csvData.TargetData;
- for (int i = 0; i < targetDatas.Count; ++i)
- {
- if (targetDatas[i].Hit == selected.name || targetDatas[i].Death == selected.name || targetDatas[i].CtrlAniFileName == selected.name)
- {
- targetIDList.Add(targetDatas[i].ID);
- targetNameList.Add(targetDatas[i].ResourceName);
- }
- }
- //查询子靶子
- List<int> childTargetList = new List<int>();
- for (int i = 0; i < targetDatas.Count; ++i)
- {
- string child = targetDatas[i].Child;
- if (string.IsNullOrEmpty(child))
- {
- continue;
- }
- string[] childs = child.Split('#');
- int targetID = targetDatas[i].ID;
- foreach (string childID in childs)
- {
- int childTargetID = int.Parse(childID);
- for (int j = 0; j < targetIDList.Count; ++j)
- {
- if (childTargetID == targetIDList[j] && !childTargetList.Contains(targetID))
- {
- childTargetList.Add(targetID);
- }
- }
- }
- }
- //查询重生靶子
- List<int> reliveTargetList = new List<int>();
- for (int i = 0; i < targetDatas.Count; ++i)
- {
- int targetID = targetDatas[i].ID;
- int rID = targetDatas[i].ReID;
- for (int j = 0; j < targetIDList.Count; ++j)
- {
- if (rID == targetIDList[j] && !reliveTargetList.Contains(targetID))
- {
- reliveTargetList.Add(targetID);
- }
- }
- }
- List<int> levelList = new List<int>();
- var targetGroup = DataManager.Instance.csvData.TargetGroup;
- for (int i = 0; i < targetGroup.Count; ++i)
- {
- int targetID = targetGroup[i].TargetID;
- int levelID = targetGroup[i].GroupID;
- InsertLevelID(targetID, levelID, targetIDList, levelList);
- InsertLevelID(targetID, levelID, childTargetList, levelList);
- InsertLevelID(targetID, levelID, reliveTargetList, levelList);
- }
- levelList.Sort();
- Debug.Log(string.Format("动画[{0}] \n所属靶子名称:{1} \n所属靶子ID:{2} \n所属关卡ID:{3}", selected.name, List2String(targetNameList), List2String(targetIDList), List2String(levelList)));
- }
- [MenuItem("Assets/查找靶子的使用情况")]
- public static void FindWhereTarget()
- {
- DataManager.Instance.InitData();
- GameObject selected = Selection.activeObject as GameObject;
- FindTargetByName(selected.name);
- }
- private static void FindTargetByName(string targetName)
- {
- List<int> targetIDList = new List<int>();
- var targetDatas = DataManager.Instance.csvData.TargetData;
- for (int i = 0; i < targetDatas.Count; ++i)
- {
- if (targetDatas[i].ResourceName == targetName)
- {
- targetIDList.Add(targetDatas[i].ID);
- }
- }
- //查询子靶子
- List<int> childTargetList = new List<int>();
- for (int i = 0; i < targetDatas.Count; ++i)
- {
- string child = targetDatas[i].Child;
- if (string.IsNullOrEmpty(child))
- {
- continue;
- }
- string[] childs = child.Split('#');
- int targetID = targetDatas[i].ID;
- foreach (string childID in childs)
- {
- int childTargetID = int.Parse(childID);
- for (int j = 0; j < targetIDList.Count; ++j)
- {
- if (childTargetID == targetIDList[j] && !childTargetList.Contains(targetID))
- {
- childTargetList.Add(targetID);
- }
- }
- }
- }
- //查询重生靶子
- List<int> reliveTargetList = new List<int>();
- for (int i = 0; i < targetDatas.Count; ++i)
- {
- int targetID = targetDatas[i].ID;
- int rID = targetDatas[i].ReID;
- for (int j = 0; j < targetIDList.Count; ++j)
- {
- if (rID == targetIDList[j] && !reliveTargetList.Contains(targetID))
- {
- reliveTargetList.Add(targetID);
- }
- }
- }
- List<int> levelList = new List<int>();
- var targetGroup = DataManager.Instance.csvData.TargetGroup;
- for (int i = 0; i < targetGroup.Count; ++i)
- {
- int targetID = targetGroup[i].TargetID;
- int levelID = targetGroup[i].GroupID;
- InsertLevelID(targetID, levelID, targetIDList, levelList);
- InsertLevelID(targetID, levelID, childTargetList, levelList);
- InsertLevelID(targetID, levelID, reliveTargetList, levelList);
- }
- levelList.Sort();
- Debug.Log(string.Format("靶子[{0}]所属关卡:{1}", targetName, List2String(levelList)));
- }
- [MenuItem("NeoGame/所有靶子的使用情况")]
- public static void FindWhereTargetAll()
- {
- DataManager.Instance.InitData();
- string path = Path.Combine(Application.dataPath, mTargetPrefab);
- List<string> targetPrefabNames = new List<string>();
- if (Directory.Exists(path))
- {
- DirectoryInfo direction = new DirectoryInfo(path);
- FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
- for (int i = 0; i < files.Length; i++)
- {
- if (files[i].Name.EndsWith(".meta"))
- {
- continue;
- }
- string[] strName = files[i].Name.Split('.');
- string filename = strName[0];
- targetPrefabNames.Add(filename);
- }
- }
- for (int i = 0; i < targetPrefabNames.Count; ++i)
- {
- FindTargetByName(targetPrefabNames[i]);
- }
- Debug.Log("所有靶子查找完毕");
- }
- private static void InsertLevelID(int targetID, int levelID, List<int> data, List<int> result)
- {
- for (int i = 0; i < data.Count; ++i)
- {
- if (data[i] == targetID && !result.Contains(levelID))
- {
- result.Add(levelID);
- }
- }
- }
- private static string List2String<T>(List<T> list)
- {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < list.Count; ++i)
- {
- sb.Append(list[i]);
- if (i != list.Count - 1)
- {
- sb.Append(",");
- }
- }
- string result = sb.ToString();
- if (string.IsNullOrEmpty(result))
- {
- sb.Append("无");
- }
- return sb.ToString();
- }
- }
|