[opt] CheckSettings中检查ScriptingBackend及ApiCompatibleLevel,切换为正确的值

main
walon 2023-05-06 12:28:03 +08:00
parent b17751b8a8
commit f63bbc8a52
1 changed files with 25 additions and 2 deletions

View File

@ -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();