BundleHelper.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using UnityEngine;
  7. namespace Model
  8. {
  9. public static class BundleHelper
  10. {
  11. public static async Task DownloadBundle()
  12. {
  13. Game.Scene.GetComponent<EventComponent>().Run(EventIdType.LoadingBegin);
  14. await StartDownLoadResources();
  15. Game.Scene.GetComponent<EventComponent>().Run(EventIdType.LoadingFinish);
  16. }
  17. public static async Task StartDownLoadResources()
  18. {
  19. if (Define.IsAsync)
  20. {
  21. //string url = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/StreamingAssets";
  22. //try
  23. //{
  24. // using (WWWAsync wwwAsync = EntityFactory.Create<WWWAsync>())
  25. // {
  26. // await wwwAsync.DownloadAsync(url);
  27. // ResourcesComponent.AssetBundleManifestObject = wwwAsync.www.assetBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
  28. // wwwAsync.www.assetBundle.Unload(false);
  29. // }
  30. //}
  31. //catch (Exception e)
  32. //{
  33. // Log.Error($"下载错误: {url} {e}");
  34. // return;
  35. //}
  36. try
  37. {
  38. using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.AddComponent<BundleDownloaderComponent>())
  39. {
  40. await bundleDownloaderComponent.StartAsync();
  41. }
  42. Log.Debug("11111111111111111111111111111111");
  43. Game.Scene.GetComponent<ResourcesComponent>().LoadOneBundle("StreamingAssets");
  44. ResourcesComponent.AssetBundleManifestObject = Game.Scene.GetComponent<ResourcesComponent>().GetAsset<AssetBundleManifest>("StreamingAssets", "AssetBundleManifest");
  45. Log.Debug("111111111111111111111111111111112");
  46. }
  47. catch (Exception e)
  48. {
  49. Log.Error(e.ToString());
  50. }
  51. }
  52. }
  53. }
  54. }