BuildDllHelper.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.IO;
  2. using HybridCLR.Editor;
  3. using UnityEditor;
  4. using UnityEngine;
  5. using GFGGame;
  6. using HybridCLR.Editor.Commands;
  7. namespace GFGEditor
  8. {
  9. public class BuildDllHelper
  10. {
  11. [InitializeOnLoadMethod]
  12. public static void Init()
  13. {
  14. AssetBundleHelper.BuildHotUpdateDll = BuildHotUpdateDll;
  15. }
  16. public static void BuildHotUpdateDll()
  17. {
  18. CompileDllCommand.CompileDllActiveBuildTarget();
  19. CopyHotUpdateAssembliesToStreamingAssets();
  20. }
  21. public static void CopyHotUpdateAssembliesToStreamingAssets()
  22. {
  23. var target = EditorUserBuildSettings.activeBuildTarget;
  24. string hotfixDllSrcDir = SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target);
  25. string hotfixAssembliesDstDir = LauncherConfig.DllDirHotfix;
  26. if (!Directory.Exists(LauncherConfig.DllDirHotfix))
  27. {
  28. Directory.CreateDirectory(LauncherConfig.DllDirHotfix);
  29. }
  30. foreach (var dll in SettingsUtil.HotUpdateAssemblyFiles)
  31. {
  32. string dllPath = $"{hotfixDllSrcDir}/{dll}";
  33. string dllBytesPath = $"{hotfixAssembliesDstDir}{dll}.bytes";
  34. File.Copy(dllPath, dllBytesPath, true);
  35. Debug.Log($"[CopyHotUpdateAssembliesToStreamingAssets] copy hotfix dll {dllPath} -> {dllBytesPath}");
  36. }
  37. }
  38. public static void CopyAOTAssembliesToStreamingAssets()
  39. {
  40. var target = EditorUserBuildSettings.activeBuildTarget;
  41. string aotAssembliesSrcDir = SettingsUtil.GetAssembliesPostIl2CppStripDir(target);
  42. string aotAssembliesDstDir = LauncherConfig.DllDirAOT;
  43. if(!Directory.Exists(LauncherConfig.DllDirAOT))
  44. {
  45. Directory.CreateDirectory(LauncherConfig.DllDirAOT);
  46. }
  47. foreach (var dll in HotUpdateCodeLoader.AOTMetaAssemblyNames)
  48. {
  49. string srcDllPath = $"{aotAssembliesSrcDir}/{dll}";
  50. if (!File.Exists(srcDllPath))
  51. {
  52. Debug.LogError($"ab中添加AOT补充元数据dll:{srcDllPath} 时发生错误,文件不存在。裁剪后的AOT dll在BuildPlayer时才能生成,因此需要你先构建一次游戏App后再打包。");
  53. continue;
  54. }
  55. string dllBytesPath = $"{aotAssembliesDstDir}{dll}.bytes";
  56. File.Copy(srcDllPath, dllBytesPath, true);
  57. Debug.Log($"[CopyAOTAssembliesToStreamingAssets] copy AOT dll {srcDllPath} -> {dllBytesPath}");
  58. }
  59. }
  60. }
  61. }