源战役客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

88 linhas
3.7 KiB

4 semanas atrás
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEditor;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Collections.Generic;
  9. using System.Reflection;
  10. public static class FindReferences
  11. {
  12. private static PropertyInfo inspectorMode = typeof(SerializedObject).GetProperty("inspectorMode", BindingFlags.NonPublic | BindingFlags.Instance);
  13. public static long GetFileID(this Object target)
  14. {
  15. SerializedObject serializedObject = new SerializedObject(target);
  16. inspectorMode.SetValue(serializedObject, InspectorMode.Debug, null);
  17. SerializedProperty localIdProp = serializedObject.FindProperty("m_LocalIdentfierInFile");
  18. return localIdProp.longValue;
  19. }
  20. [MenuItem("Assets/Find References", false)]
  21. static void Find()
  22. {
  23. EditorSettings.serializationMode = SerializationMode.ForceText;
  24. string path = AssetDatabase.GetAssetPath(Selection.activeObject);
  25. if (!string.IsNullOrEmpty(path))
  26. {
  27. Debug.Log("开始查找哪里引用到资源:"+path);
  28. string guid = AssetDatabase.AssetPathToGUID(path);
  29. //string guid = FindReferences.GetFileID(Selection.activeObject).ToString();
  30. // Debug.Log("guid : " + guid);
  31. List<string> withoutExtensions = new List<string>() { ".prefab", ".unity", ".mat", ".asset" };
  32. string[] files = Directory.GetFiles(Application.dataPath, "*.*", SearchOption.AllDirectories)
  33. .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray();
  34. int startIndex = 0;
  35. EditorApplication.update = delegate ()
  36. {
  37. string file = files[startIndex];
  38. bool isCancel = EditorUtility.DisplayCancelableProgressBar("匹配资源中", file, (float)startIndex / (float)files.Length);
  39. if (Regex.IsMatch(File.ReadAllText(file), guid))
  40. {
  41. Object find_obj = AssetDatabase.LoadAssetAtPath<Object>(GetRelativeAssetsPath(file));
  42. Debug.Log(file+"引用到该资源", find_obj);
  43. string extension = Path.GetExtension(file);
  44. // Debug.Log("extension "+extension);
  45. if (extension == ".prefab")
  46. {
  47. int select_index = EditorUtility.DisplayDialogComplex("找到了", file+"引用到该资源", "关闭", "继续查找", "打开界面");
  48. // Debug.Log("select index "+select_index);
  49. isCancel = (select_index==0 || select_index==2);
  50. if (select_index == 2)
  51. {
  52. U3DExtends.UIEditorHelper.LoadLayoutByPath(file);
  53. }
  54. }
  55. else
  56. {
  57. isCancel = EditorUtility.DisplayDialog("找到了", file+"引用到该资源", "关闭", "继续查找");
  58. }
  59. }
  60. startIndex++;
  61. if (isCancel || startIndex >= files.Length)
  62. {
  63. EditorUtility.ClearProgressBar();
  64. EditorApplication.update = null;
  65. startIndex = 0;
  66. Debug.Log("匹配结束");
  67. }
  68. };
  69. }
  70. }
  71. [MenuItem("Assets/Find References", true)]
  72. static private bool VFind()
  73. {
  74. string path = AssetDatabase.GetAssetPath(Selection.activeObject);
  75. return (!string.IsNullOrEmpty(path));
  76. }
  77. static private string GetRelativeAssetsPath(string path)
  78. {
  79. return "Assets" + Path.GetFullPath(path).Replace(Path.GetFullPath(Application.dataPath), "").Replace('\\', '/');
  80. }
  81. }