EditorResHelper.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using UnityEditor;
  4. namespace ET
  5. {
  6. public class EditorResHelper
  7. {
  8. public static void SaveAssets(UnityEngine.Object asset)
  9. {
  10. EditorUtility.SetDirty(asset);
  11. AssetDatabase.SaveAssets();
  12. AssetDatabase.Refresh();
  13. }
  14. /// <summary>
  15. /// 获取文件夹内所有的预制跟场景路径
  16. /// </summary>
  17. /// <param name="srcPath">源文件夹</param>
  18. /// <param name="subDire">是否获取子文件夹</param>
  19. /// <returns></returns>
  20. public static List<string> GetPrefabsAndScenes(string srcPath)
  21. {
  22. List<string> paths = new List<string>();
  23. FileHelper.GetAllFiles(paths, srcPath);
  24. List<string> files = new List<string>();
  25. foreach (string str in paths)
  26. {
  27. if (str.EndsWith(".prefab") || str.EndsWith(".unity"))
  28. {
  29. files.Add(str);
  30. }
  31. }
  32. return files;
  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. }