CheckSettings.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using UnityEditor.Build;
  7. using UnityEditor.Build.Reporting;
  8. using UnityEngine;
  9. namespace HybridCLR.Editor.BuildProcessors
  10. {
  11. internal class CheckSettings : IPreprocessBuildWithReport
  12. {
  13. public int callbackOrder => 0;
  14. public void OnPreprocessBuild(BuildReport report)
  15. {
  16. HybridCLRSettings globalSettings = SettingsUtil.HybridCLRSettings;
  17. #if !UNITY_2020_1_OR_NEWER || !UNITY_IOS
  18. if (!globalSettings.enable || globalSettings.useGlobalIl2cpp)
  19. {
  20. string oldIl2cppPath = Environment.GetEnvironmentVariable("UNITY_IL2CPP_PATH");
  21. if (!string.IsNullOrEmpty(oldIl2cppPath))
  22. {
  23. Environment.SetEnvironmentVariable("UNITY_IL2CPP_PATH", "");
  24. Debug.Log($"[CheckSettings] 清除 UNITY_IL2CPP_PATH, 旧值为:'{oldIl2cppPath}'");
  25. }
  26. }
  27. else
  28. {
  29. string curIl2cppPath = Environment.GetEnvironmentVariable("UNITY_IL2CPP_PATH");
  30. if (curIl2cppPath != SettingsUtil.LocalIl2CppDir)
  31. {
  32. Environment.SetEnvironmentVariable("UNITY_IL2CPP_PATH", SettingsUtil.LocalIl2CppDir);
  33. Debug.Log($"[CheckSettings] UNITY_IL2CPP_PATH 当前值为:'{curIl2cppPath}',更新为:'{SettingsUtil.LocalIl2CppDir}'");
  34. }
  35. }
  36. #endif
  37. if (!globalSettings.enable)
  38. {
  39. return;
  40. }
  41. if (UnityEditor.PlayerSettings.gcIncremental)
  42. {
  43. Debug.LogError($"[CheckSettings] HybridCLR不支持增量式GC,已经自动将该选项关闭");
  44. UnityEditor.PlayerSettings.gcIncremental = false;
  45. }
  46. var installer = new Installer.InstallerController();
  47. if (!installer.HasInstalledHybridCLR())
  48. {
  49. throw new Exception($"你没有初始化HybridCLR,请通过菜单'HybridCLR/Installer'安装");
  50. }
  51. HybridCLRSettings gs = SettingsUtil.HybridCLRSettings;
  52. if (((gs.hotUpdateAssemblies?.Length + gs.hotUpdateAssemblyDefinitions?.Length) ?? 0) == 0)
  53. {
  54. Debug.LogWarning("[CheckSettings] HybridCLRSettings中未配置任何热更新模块");
  55. }
  56. }
  57. }
  58. }