CheckSettings.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using HybridCLR.Editor.Settings;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using UnityEditor;
  8. using UnityEditor.Build;
  9. using UnityEditor.Build.Reporting;
  10. using UnityEngine;
  11. using static UnityEngine.GraphicsBuffer;
  12. namespace HybridCLR.Editor.BuildProcessors
  13. {
  14. internal class CheckSettings : IPreprocessBuildWithReport
  15. {
  16. public int callbackOrder => 0;
  17. public void OnPreprocessBuild(BuildReport report)
  18. {
  19. HybridCLRSettings globalSettings = SettingsUtil.HybridCLRSettings;
  20. if (!globalSettings.enable || globalSettings.useGlobalIl2cpp)
  21. {
  22. string oldIl2cppPath = Environment.GetEnvironmentVariable("UNITY_IL2CPP_PATH");
  23. if (!string.IsNullOrEmpty(oldIl2cppPath))
  24. {
  25. Environment.SetEnvironmentVariable("UNITY_IL2CPP_PATH", "");
  26. Debug.Log($"[CheckSettings] clean process environment variable: UNITY_IL2CPP_PATH, old vlaue:'{oldIl2cppPath}'");
  27. }
  28. }
  29. else
  30. {
  31. string curIl2cppPath = Environment.GetEnvironmentVariable("UNITY_IL2CPP_PATH");
  32. if (curIl2cppPath != SettingsUtil.LocalIl2CppDir)
  33. {
  34. Environment.SetEnvironmentVariable("UNITY_IL2CPP_PATH", SettingsUtil.LocalIl2CppDir);
  35. Debug.Log($"[CheckSettings] UNITY_IL2CPP_PATH old value:'{curIl2cppPath}', new value:'{SettingsUtil.LocalIl2CppDir}'");
  36. }
  37. }
  38. if (!globalSettings.enable)
  39. {
  40. return;
  41. }
  42. BuildTargetGroup buildTargetGroup = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget);
  43. ScriptingImplementation curScriptingImplementation = PlayerSettings.GetScriptingBackend(buildTargetGroup);
  44. ScriptingImplementation targetScriptingImplementation = ScriptingImplementation.IL2CPP;
  45. if (curScriptingImplementation != targetScriptingImplementation)
  46. {
  47. Debug.LogError($"[CheckSettings] current ScriptingBackend:{curScriptingImplementation},have been switched to:{targetScriptingImplementation} automatically");
  48. PlayerSettings.SetScriptingBackend(buildTargetGroup, targetScriptingImplementation);
  49. }
  50. var installer = new Installer.InstallerController();
  51. if (!installer.HasInstalledHybridCLR())
  52. {
  53. throw new BuildFailedException($"You have not initialized HybridCLR, please install it via menu 'HybridCLR/Installer'");
  54. }
  55. if (installer.PackageVersion != installer.InstalledLibil2cppVersion)
  56. {
  57. throw new BuildFailedException($"You must run `HybridCLR/Installer` after upgrading package");
  58. }
  59. HybridCLRSettings gs = SettingsUtil.HybridCLRSettings;
  60. if (((gs.hotUpdateAssemblies?.Length + gs.hotUpdateAssemblyDefinitions?.Length) ?? 0) == 0)
  61. {
  62. Debug.LogWarning("[CheckSettings] No hot update modules configured in HybridCLRSettings");
  63. }
  64. }
  65. }
  66. }