EditorResHelper.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Collections.Generic;
  2. using System.IO;
  3. namespace Model
  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> GetAllPath(string srcPath, bool subDire)
  14. {
  15. List<string> paths = new List<string>();
  16. string[] files = Directory.GetFiles(srcPath);
  17. foreach (string str in files)
  18. {
  19. if (str.EndsWith(".prefab"))
  20. {
  21. paths.Add(str);
  22. }
  23. }
  24. if (subDire)
  25. {
  26. foreach (string subPath in Directory.GetDirectories(srcPath))
  27. {
  28. List<string> subFiles = GetAllPath(subPath, true);
  29. paths.AddRange(subFiles);
  30. }
  31. }
  32. return paths;
  33. }
  34. /// <summary>
  35. /// 获取文件夹内所有资源路径
  36. /// </summary>
  37. /// <param name="srcPath">源文件夹</param>
  38. /// <param name="subDire">是否获取子文件夹</param>
  39. /// <returns></returns>
  40. public static List<string> GetAllResourcePath(string srcPath, bool subDire)
  41. {
  42. List<string> paths = new List<string>();
  43. string[] files = Directory.GetFiles(srcPath);
  44. foreach (string str in files)
  45. {
  46. if (str.EndsWith(".meta"))
  47. {
  48. continue;
  49. }
  50. paths.Add(str);
  51. }
  52. if (subDire)
  53. {
  54. foreach (string subPath in Directory.GetDirectories(srcPath))
  55. {
  56. List<string> subFiles = GetAllResourcePath(subPath, true);
  57. paths.AddRange(subFiles);
  58. }
  59. }
  60. return paths;
  61. }
  62. }
  63. }