diff --git a/Editor/BuildProcessors/CheckSettings.cs b/Editor/BuildProcessors/CheckSettings.cs index 2cf0f00..bad1420 100644 --- a/Editor/BuildProcessors/CheckSettings.cs +++ b/Editor/BuildProcessors/CheckSettings.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using UnityEditor; using UnityEditor.Build; using UnityEditor.Build.Reporting; using UnityEngine; @@ -40,10 +41,32 @@ namespace HybridCLR.Editor.BuildProcessors { return; } - if (UnityEditor.PlayerSettings.gcIncremental) + if (PlayerSettings.gcIncremental) { Debug.LogError($"[CheckSettings] HybridCLR不支持增量式GC,已经自动将该选项关闭"); - UnityEditor.PlayerSettings.gcIncremental = false; + PlayerSettings.gcIncremental = false; + } + BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup; + ScriptingImplementation curScriptingImplementation = PlayerSettings.GetScriptingBackend(buildTargetGroup); + ScriptingImplementation targetScriptingImplementation = ScriptingImplementation.IL2CPP; + if (curScriptingImplementation != targetScriptingImplementation) + { + Debug.LogError($"[CheckSettings] 当前ScriptingBackend是:{curScriptingImplementation},已经自动切换为:{targetScriptingImplementation}"); + PlayerSettings.SetScriptingBackend(buildTargetGroup, targetScriptingImplementation); + } + ApiCompatibilityLevel curApiCompatibilityLevel = PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup); +#if UNITY_2021_1_OR_NEWER + ApiCompatibilityLevel targetApiCompatibilityLevel = ApiCompatibilityLevel.NET_Unity_4_8; +#else + ApiCompatibilityLevel targetApiCompatibilityLevel = ApiCompatibilityLevel.NET_4_6; +#endif + + + if (curApiCompatibilityLevel != targetApiCompatibilityLevel) + { + Debug.LogError($"[CheckSettings] 当前ApiCompatibilityLevel是:{curApiCompatibilityLevel},已经自动切换为 {targetApiCompatibilityLevel}。由于下一次打包才生效,主动打断本次打包。"); + PlayerSettings.SetApiCompatibilityLevel(buildTargetGroup, ApiCompatibilityLevel.NET_4_6); + throw new BuildFailedException("ApiCompatibilityLevel error"); } var installer = new Installer.InstallerController();