EditorHelper.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace Mirror
  6. {
  7. public static class EditorHelper
  8. {
  9. public static string FindPath<T>()
  10. {
  11. string typeName = typeof(T).Name;
  12. string[] guidsFound = AssetDatabase.FindAssets($"t:Script {typeName}");
  13. if (guidsFound.Length >= 1 && !string.IsNullOrWhiteSpace(guidsFound[0]))
  14. {
  15. if (guidsFound.Length > 1)
  16. {
  17. Debug.LogWarning($"Found more than one{typeName}");
  18. }
  19. string path = AssetDatabase.GUIDToAssetPath(guidsFound[0]);
  20. return Path.GetDirectoryName(path);
  21. }
  22. else
  23. {
  24. Debug.LogError($"Could not find path of {typeName}");
  25. return string.Empty;
  26. }
  27. }
  28. public static IEnumerable<string> IterateOverProject(string filter)
  29. {
  30. foreach (string guid in AssetDatabase.FindAssets(filter))
  31. {
  32. yield return AssetDatabase.GUIDToAssetPath(guid);
  33. }
  34. }
  35. }
  36. }