BuildDllHelper.cs 2.5 KB

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