AddressableAssetInfoExt.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using XGame.Framework.Asset;
  2. using XGame.Framework.Asset.Addressable.Data;
  3. using System;
  4. using UnityEditor;
  5. namespace XGame.Editor.Asset
  6. {
  7. public static class AddressableAssetInfoExt
  8. {
  9. /// <summary>
  10. /// 编辑器扩展方法
  11. /// </summary>
  12. /// <param name="assetInfo"></param>
  13. /// <returns></returns>
  14. public static string GetAssetPath(this AssetInfo assetInfo)
  15. {
  16. return AssetDatabase.GUIDToAssetPath(assetInfo.assetGUID);
  17. }
  18. /// <summary>
  19. /// 是否内置资源
  20. /// </summary>
  21. /// <param name="assetInfo"></param>
  22. /// <returns></returns>
  23. public static bool IsBuiltIn(this AssetInfo assetInfo)
  24. {
  25. var assetPath = assetInfo.GetAssetPath();
  26. if (!string.IsNullOrEmpty(assetPath) && assetPath.IndexOf(PathDefine.PackageRelative, StringComparison.Ordinal) == 0)
  27. {
  28. return true;
  29. }
  30. return false;
  31. }
  32. ///// <summary>
  33. ///// 编辑器扩展方法
  34. ///// </summary>
  35. ///// <param name="assetInfo"></param>
  36. ///// <param name="id"></param>
  37. //public static void SetAddressableId(this AddressableAssetInfo assetInfo, long id)
  38. //{
  39. // var fileInfo = assetInfo.GetType().GetField("addressableId", BindingFlags.NonPublic | BindingFlags.Instance);
  40. // fileInfo?.SetValue(assetInfo, id);
  41. //}
  42. ///// <summary>
  43. ///// 编辑器扩展方法
  44. ///// </summary>
  45. ///// <param name="assetInfo"></param>
  46. ///// <param name="name"></param>
  47. //public static void SetAddressableName(this AddressableAssetInfo assetInfo, string name)
  48. //{
  49. // var fileInfo = assetInfo.GetType().GetField("addressableName", BindingFlags.NonPublic | BindingFlags.Instance);
  50. // fileInfo?.SetValue(assetInfo, name);
  51. //}
  52. ///// <summary>
  53. ///// 编辑器扩展方法
  54. ///// </summary>
  55. ///// <param name="assetInfo"></param>
  56. ///// <param name="guid"></param>
  57. //public static void SetGUID(this AddressableAssetInfo assetInfo, string guid)
  58. //{
  59. // var fileInfo = assetInfo.GetType().GetField("assetGUID", BindingFlags.NonPublic | BindingFlags.Instance);
  60. // fileInfo?.SetValue(assetInfo, guid);
  61. //}
  62. }
  63. }