2022-09-22 08:56:07 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-05-06 12:28:03 +08:00
|
|
|
|
using UnityEditor;
|
2022-09-22 08:56:07 +08:00
|
|
|
|
using UnityEditor.Build;
|
|
|
|
|
using UnityEditor.Build.Reporting;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace HybridCLR.Editor.BuildProcessors
|
|
|
|
|
{
|
|
|
|
|
internal class CheckSettings : IPreprocessBuildWithReport
|
|
|
|
|
{
|
|
|
|
|
public int callbackOrder => 0;
|
|
|
|
|
|
|
|
|
|
public void OnPreprocessBuild(BuildReport report)
|
|
|
|
|
{
|
2022-10-09 20:53:13 +08:00
|
|
|
|
HybridCLRSettings globalSettings = SettingsUtil.HybridCLRSettings;
|
|
|
|
|
if (!globalSettings.enable || globalSettings.useGlobalIl2cpp)
|
2022-09-22 08:56:07 +08:00
|
|
|
|
{
|
|
|
|
|
string oldIl2cppPath = Environment.GetEnvironmentVariable("UNITY_IL2CPP_PATH");
|
|
|
|
|
if (!string.IsNullOrEmpty(oldIl2cppPath))
|
|
|
|
|
{
|
|
|
|
|
Environment.SetEnvironmentVariable("UNITY_IL2CPP_PATH", "");
|
|
|
|
|
Debug.Log($"[CheckSettings] 清除 UNITY_IL2CPP_PATH, 旧值为:'{oldIl2cppPath}'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string curIl2cppPath = Environment.GetEnvironmentVariable("UNITY_IL2CPP_PATH");
|
|
|
|
|
if (curIl2cppPath != SettingsUtil.LocalIl2CppDir)
|
|
|
|
|
{
|
|
|
|
|
Environment.SetEnvironmentVariable("UNITY_IL2CPP_PATH", SettingsUtil.LocalIl2CppDir);
|
|
|
|
|
Debug.Log($"[CheckSettings] UNITY_IL2CPP_PATH 当前值为:'{curIl2cppPath}',更新为:'{SettingsUtil.LocalIl2CppDir}'");
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-09 16:13:23 +08:00
|
|
|
|
if (!globalSettings.enable)
|
2022-09-22 08:56:07 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-05-06 12:28:03 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
2022-09-22 08:56:07 +08:00
|
|
|
|
|
|
|
|
|
var installer = new Installer.InstallerController();
|
|
|
|
|
if (!installer.HasInstalledHybridCLR())
|
|
|
|
|
{
|
2023-06-15 09:57:15 +08:00
|
|
|
|
throw new BuildFailedException($"你没有初始化HybridCLR,请通过菜单'HybridCLR/Installer'安装");
|
2022-09-22 08:56:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-09 20:53:13 +08:00
|
|
|
|
HybridCLRSettings gs = SettingsUtil.HybridCLRSettings;
|
2022-09-22 08:56:07 +08:00
|
|
|
|
if (((gs.hotUpdateAssemblies?.Length + gs.hotUpdateAssemblyDefinitions?.Length) ?? 0) == 0)
|
|
|
|
|
{
|
2022-11-05 22:22:39 +08:00
|
|
|
|
Debug.LogWarning("[CheckSettings] HybridCLRSettings中未配置任何热更新模块");
|
2022-09-22 08:56:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|