BundleHelper.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.IO;
  3. using System.Threading.Tasks;
  4. using UnityEngine;
  5. namespace ETModel
  6. {
  7. public static class BundleHelper
  8. {
  9. public static async ETTask DownloadBundle()
  10. {
  11. if (Define.IsAsync)
  12. {
  13. try
  14. {
  15. using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.AddComponent<BundleDownloaderComponent>())
  16. {
  17. await bundleDownloaderComponent.StartAsync();
  18. Game.EventSystem.Run(EventIdType.LoadingBegin);
  19. await bundleDownloaderComponent.DownloadAsync();
  20. }
  21. Game.EventSystem.Run(EventIdType.LoadingFinish);
  22. Game.Scene.GetComponent<ResourcesComponent>().LoadOneBundle("StreamingAssets");
  23. ResourcesComponent.AssetBundleManifestObject = (AssetBundleManifest)Game.Scene.GetComponent<ResourcesComponent>().GetAsset("StreamingAssets", "AssetBundleManifest");
  24. }
  25. catch (Exception e)
  26. {
  27. Log.Error(e);
  28. }
  29. }
  30. }
  31. public static string GetBundleMD5(VersionConfig streamingVersionConfig, string bundleName)
  32. {
  33. string path = Path.Combine(PathHelper.AppHotfixResPath, bundleName);
  34. if (File.Exists(path))
  35. {
  36. return MD5Helper.FileMD5(path);
  37. }
  38. if (streamingVersionConfig.FileInfoDict.ContainsKey(bundleName))
  39. {
  40. return streamingVersionConfig.FileInfoDict[bundleName].MD5;
  41. }
  42. return "";
  43. }
  44. }
  45. }