You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

61 lines
2.2 KiB

  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. public class FindReferences
  10. {
  11. [MenuItem("Assets/查找所有引用", false, 10)]
  12. static private void Find()
  13. {
  14. EditorSettings.serializationMode = SerializationMode.ForceText;
  15. string path = AssetDatabase.GetAssetPath(Selection.activeObject);
  16. if (!string.IsNullOrEmpty(path))
  17. {
  18. string guid = AssetDatabase.AssetPathToGUID(path);
  19. List<string> withoutExtensions = new List<string>() { ".prefab", ".unity", ".mat", ".asset" };
  20. string[] files = Directory.GetFiles(Application.dataPath, "*.*", SearchOption.AllDirectories)
  21. .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray();
  22. int startIndex = 0;
  23. EditorApplication.update = delegate()
  24. {
  25. string file = files[startIndex];
  26. bool isCancel = EditorUtility.DisplayCancelableProgressBar("匹配资源中", file, (float)startIndex / (float)files.Length);
  27. if (Regex.IsMatch(File.ReadAllText(file), guid))
  28. {
  29. Debug.Log(file, AssetDatabase.LoadAssetAtPath<Object>(GetRelativeAssetsPath(file)));
  30. }
  31. startIndex++;
  32. if (isCancel || startIndex >= files.Length)
  33. {
  34. EditorUtility.ClearProgressBar();
  35. EditorApplication.update = null;
  36. startIndex = 0;
  37. Debug.Log("匹配结束");
  38. }
  39. };
  40. }
  41. }
  42. [MenuItem("Assets/Find References", true)]
  43. static private bool VFind()
  44. {
  45. string path = AssetDatabase.GetAssetPath(Selection.activeObject);
  46. return (!string.IsNullOrEmpty(path));
  47. }
  48. static private string GetRelativeAssetsPath(string path)
  49. {
  50. return "Assets" + Path.GetFullPath(path).Replace(Path.GetFullPath(Application.dataPath), "").Replace('\\', '/');
  51. }
  52. }