AssetModuleExt.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using UnityEngine;
  2. namespace XGame.Framework.Asset
  3. {
  4. /// <summary>
  5. /// IAssetModule扩展
  6. /// </summary>
  7. public static class AssetModuleExt
  8. {
  9. #region 内部扩展方法
  10. private static bool IsRegister(this IAssetModule module, object asset, object parent)
  11. {
  12. if (module == null || asset == null || parent == null)
  13. return false;
  14. return (module as AssetModule)?.IsRegister(asset.GetLongHashCode(), parent.GetLongHashCode()) ?? false;
  15. }
  16. private static bool Register(this IAssetModule module, object asset, object parent)
  17. {
  18. if (module == null || asset == null || parent == null)
  19. return false;
  20. return (module as AssetModule)?.Register(asset.GetLongHashCode(), parent.GetLongHashCode()) ?? false;
  21. }
  22. private static bool UnRegister(this IAssetModule module, object asset, object parent)
  23. {
  24. if (module == null || asset == null || parent == null)
  25. return false;
  26. return (module as AssetModule)?.UnRegister(asset.GetLongHashCode(), parent.GetLongHashCode()) ?? false;
  27. }
  28. #endregion
  29. #region GameObject
  30. ///// <summary>
  31. ///// 不推荐业务使用同步加载,先屏蔽
  32. ///// 同步加载 GameObject
  33. ///// 使用该接口加载的资源严禁使用Object.Destroy销毁,只能使用Recycle(obj)方法回收
  34. ///// </summary>
  35. ///// <param name="module"></param>
  36. ///// <param name="addressableName"></param>
  37. ///// <returns></returns>
  38. //public static GameObject LoadSync(this IAssetModule module, string addressableName)
  39. //{
  40. // return module.LoadSync<GameObject>(addressableName);
  41. //}
  42. /// <summary>
  43. /// 异步加载 GameObject
  44. /// 使用该接口加载的资源严禁使用Object.Destroy销毁,只能使用Recycle(obj)方法回收
  45. /// </summary>
  46. /// <param name="module"></param>
  47. /// <param name="addressableName"></param>
  48. /// <returns></returns>
  49. public static IAssetLoadAsync<GameObject> LoadAsync(this IAssetModule module, string addressableName)
  50. {
  51. return module.LoadAsync<GameObject>(addressableName);
  52. }
  53. /// <summary>
  54. /// 回收GameObject对象接口
  55. /// </summary>
  56. /// <param name="module"></param>
  57. /// <param name="go"></param>
  58. /// <param name="destroy"></param>
  59. public static void Recycle(this IAssetModule module, GameObject go, bool destroy)
  60. {
  61. if (module == null || go == null) return;
  62. if (destroy)
  63. {
  64. (module as AssetModule)?.Recycle(go, true);
  65. }
  66. else
  67. {
  68. module.Recycle(go);
  69. }
  70. }
  71. #endregion
  72. }
  73. }