BundleAssetRequest.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. public class BundleAssetRequest : AssetRequest
  6. {
  7. protected readonly string assetBundleName;
  8. protected BundleRequest BundleRequest;
  9. protected List<BundleRequest> children = new List<BundleRequest>();
  10. public BundleAssetRequest(string bundle)
  11. {
  12. assetBundleName = bundle;
  13. }
  14. internal override void Load()
  15. {
  16. BundleRequest = LoadModule.LoadBundle(assetBundleName);
  17. var names = LoadModule.GetAllDependencies(assetBundleName);
  18. foreach (var item in names)
  19. children.Add(LoadModule.LoadBundle(item));
  20. var assetName = Path.GetFileName(name);
  21. var ab = BundleRequest.assetBundle;
  22. if (ab != null)
  23. asset = ab.LoadAsset(assetName, assetType);
  24. if (asset == null)
  25. error = "asset == null";
  26. LoadState = AssetLoadState.Loaded;
  27. }
  28. internal override void Unload()
  29. {
  30. if (BundleRequest != null)
  31. {
  32. BundleRequest.Release();
  33. BundleRequest = null;
  34. }
  35. if (children.Count > 0)
  36. {
  37. foreach (var item in children)
  38. item.Release();
  39. children.Clear();
  40. }
  41. asset = null;
  42. }
  43. }