BuildDllHelper.cs 2.7 KB

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