BuildDllHelper.cs 2.1 KB

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