BundleHelper.cs 933 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Threading.Tasks;
  3. using UnityEngine;
  4. namespace ETModel
  5. {
  6. public static class BundleHelper
  7. {
  8. public static async Task DownloadBundle()
  9. {
  10. Game.EventSystem.Run(EventIdType.LoadingBegin);
  11. await StartDownLoadResources();
  12. Game.EventSystem.Run(EventIdType.LoadingFinish);
  13. }
  14. public static async Task StartDownLoadResources()
  15. {
  16. if (Define.IsAsync)
  17. {
  18. try
  19. {
  20. using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.AddComponent<BundleDownloaderComponent>())
  21. {
  22. await bundleDownloaderComponent.StartAsync();
  23. }
  24. Game.Scene.GetComponent<ResourcesComponent>().LoadOneBundle("StreamingAssets");
  25. ResourcesComponent.AssetBundleManifestObject = (AssetBundleManifest)Game.Scene.GetComponent<ResourcesComponent>().GetAsset("StreamingAssets", "AssetBundleManifest");
  26. }
  27. catch (Exception e)
  28. {
  29. Log.Error(e);
  30. }
  31. }
  32. }
  33. }
  34. }