EditorHelper.cs 861 B

12345678910111213141516171819202122232425262728293031
  1. using System.IO;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace Mirror
  5. {
  6. public static class EditorHelper
  7. {
  8. public static string FindPath<T>()
  9. {
  10. string typeName = typeof(T).Name;
  11. string[] guidsFound = AssetDatabase.FindAssets($"t:Script " + typeName);
  12. if (guidsFound.Length >= 1 && !string.IsNullOrEmpty(guidsFound[0]))
  13. {
  14. if (guidsFound.Length > 1)
  15. {
  16. Debug.LogWarning($"Found more than one{typeName}");
  17. }
  18. string path = AssetDatabase.GUIDToAssetPath(guidsFound[0]);
  19. return Path.GetDirectoryName(path);
  20. }
  21. else
  22. {
  23. Debug.LogError($"Could not find path of {typeName}");
  24. return string.Empty;
  25. }
  26. }
  27. }
  28. }