WebBundleRequest.cs 1020 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. public class WebBundleRequest : BundleRequest
  6. {
  7. private UnityWebRequest _request;
  8. public bool cache;
  9. public Hash128 hash;
  10. public override float progress
  11. {
  12. get
  13. {
  14. if (isDone) return 1;
  15. if (LoadState == AssetLoadState.Init) return 0;
  16. if (_request == null) return 1;
  17. return _request.downloadProgress;
  18. }
  19. }
  20. internal override void Load()
  21. {
  22. _request = cache ? UnityWebRequestAssetBundle.GetAssetBundle(name, hash)
  23. : UnityWebRequestAssetBundle.GetAssetBundle(name);
  24. _request.SendWebRequest();
  25. LoadState = AssetLoadState.LoadAssetBundle;
  26. }
  27. internal override void Unload()
  28. {
  29. if (_request != null)
  30. {
  31. _request.Dispose();
  32. _request = null;
  33. }
  34. LoadState = AssetLoadState.Unload;
  35. base.Unload();
  36. }
  37. }