AssetsBundleHelper.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections.Generic;
  2. using UnityEngine.AddressableAssets;
  3. using UnityEngine.AddressableAssets.ResourceLocators;
  4. namespace ET.Client
  5. {
  6. public static class AssetsBundleHelper
  7. {
  8. public static async ETTask InitializeAsync()
  9. {
  10. IResourceLocator resourceLocator = await Addressables.InitializeAsync().Task;
  11. long downloadSize = await Addressables.GetDownloadSizeAsync(resourceLocator.Keys).Task;
  12. Log.Info($"download size: {downloadSize}");
  13. }
  14. public static async ETTask LoadCodeAsync()
  15. {
  16. List<string> codes = new List<string>()
  17. {
  18. "Model.dll",
  19. "Model.pdb",
  20. "Hotfix.dll",
  21. "Hotfix.pdb",
  22. };
  23. List<ETTask> tasks = new List<ETTask>(codes.Count);
  24. foreach (string s in codes)
  25. {
  26. tasks.Add(LoadOneDll($"Assets/Bundles/Code/{s}.bytes"));
  27. }
  28. await ETTaskHelper.WaitAll(tasks);
  29. }
  30. public static async ETTask LoadAotDllAsync()
  31. {
  32. if (Define.EnableIL2CPP)
  33. {
  34. List<ETTask> tasks = new List<ETTask>(AOTGenericReferences.PatchedAOTAssemblyList.Count);
  35. foreach (string s in AOTGenericReferences.PatchedAOTAssemblyList)
  36. {
  37. tasks.Add(LoadOneDll($"Assets/Bundles/AotDlls/{s}.bytes"));
  38. }
  39. await ETTaskHelper.WaitAll(tasks);
  40. }
  41. }
  42. private static async ETTask LoadOneDll(string s)
  43. {
  44. await ResourcesComponent.Instance.LoadAssetAsync(s);
  45. }
  46. }
  47. }