EditorResHelper.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Collections.Generic;
  2. using System.IO;
  3. namespace ET
  4. {
  5. public class EditorResHelper
  6. {
  7. /// <summary>
  8. /// 获取文件夹内所有的预制跟场景路径
  9. /// </summary>
  10. /// <param name="srcPath">源文件夹</param>
  11. /// <param name="subDire">是否获取子文件夹</param>
  12. /// <returns></returns>
  13. public static List<string> GetPrefabsAndScenes(string srcPath)
  14. {
  15. List<string> paths = new List<string>();
  16. FileHelper.GetAllFiles(paths, srcPath);
  17. List<string> files = new List<string>();
  18. foreach (string str in paths)
  19. {
  20. if (str.EndsWith(".prefab") || str.EndsWith(".unity"))
  21. {
  22. files.Add(str);
  23. }
  24. }
  25. return files;
  26. }
  27. /// <summary>
  28. /// 获取文件夹内所有资源路径
  29. /// </summary>
  30. /// <param name="srcPath">源文件夹</param>
  31. /// <param name="subDire">是否获取子文件夹</param>
  32. /// <returns></returns>
  33. public static List<string> GetAllResourcePath(string srcPath, bool subDire)
  34. {
  35. List<string> paths = new List<string>();
  36. string[] files = Directory.GetFiles(srcPath);
  37. foreach (string str in files)
  38. {
  39. if (str.EndsWith(".meta"))
  40. {
  41. continue;
  42. }
  43. paths.Add(str);
  44. }
  45. if (subDire)
  46. {
  47. foreach (string subPath in Directory.GetDirectories(srcPath))
  48. {
  49. List<string> subFiles = GetAllResourcePath(subPath, true);
  50. paths.AddRange(subFiles);
  51. }
  52. }
  53. return paths;
  54. }
  55. }
  56. }