AssetDependencyCache.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using UnityEditor;
  7. using UnityEngine;
  8. namespace YooAsset.Editor
  9. {
  10. public class AssetDependencyCache
  11. {
  12. private readonly AssetDependencyDatabase _database;
  13. /// <summary>
  14. /// 初始化资源依赖缓存系统
  15. /// </summary>
  16. public AssetDependencyCache(bool useAssetDependencyDB)
  17. {
  18. if (useAssetDependencyDB)
  19. Debug.Log("Use asset dependency database !");
  20. string databaseFilePath = "Library/AssetDependencyDB";
  21. _database = new AssetDependencyDatabase();
  22. _database.CreateDatabase(useAssetDependencyDB, databaseFilePath);
  23. if (useAssetDependencyDB)
  24. {
  25. _database.SaveDatabase();
  26. }
  27. }
  28. /// <summary>
  29. /// 获取资源的依赖列表
  30. /// </summary>
  31. /// <param name="assetPath">资源路径</param>
  32. /// <param name="recursive">递归查找所有依赖</param>
  33. /// <returns>返回依赖的资源路径集合</returns>
  34. public string[] GetDependencies(string assetPath, bool recursive = true)
  35. {
  36. // 通过本地缓存获取依赖关系
  37. return _database.GetDependencies(assetPath, recursive);
  38. // 通过Unity引擎获取依赖关系
  39. //return AssetDatabase.GetDependencies(assetPath, recursive);
  40. }
  41. }
  42. }