2022-12-16 11:03:03 +08:00
|
|
|
|
using HybridCLR.Editor.Installer;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace HybridCLR.Editor.Commands
|
|
|
|
|
{
|
|
|
|
|
public static class StripAOTDllCommand
|
|
|
|
|
{
|
|
|
|
|
[MenuItem("HybridCLR/Generate/AOTDlls", priority = 105)]
|
|
|
|
|
public static void GenerateStripedAOTDlls()
|
|
|
|
|
{
|
|
|
|
|
GenerateStripedAOTDlls(EditorUserBuildSettings.activeBuildTarget, EditorUserBuildSettings.selectedBuildTargetGroup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetLocationPathName(string buildDir, BuildTarget target)
|
|
|
|
|
{
|
|
|
|
|
switch(target)
|
|
|
|
|
{
|
|
|
|
|
case BuildTarget.StandaloneWindows:
|
|
|
|
|
case BuildTarget.StandaloneWindows64: return $"{buildDir}/{target}";
|
|
|
|
|
case BuildTarget.StandaloneOSX: return buildDir;
|
|
|
|
|
case BuildTarget.iOS: return buildDir;
|
|
|
|
|
case BuildTarget.Android: return buildDir;
|
|
|
|
|
case BuildTarget.StandaloneLinux64: return buildDir;
|
|
|
|
|
default: return buildDir;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void GenerateStripedAOTDlls(BuildTarget target, BuildTargetGroup group)
|
|
|
|
|
{
|
|
|
|
|
string outputPath = $"{SettingsUtil.HybridCLRDataDir}/StrippedAOTDllsTempProj/{target}";
|
|
|
|
|
BashUtil.RemoveDir(outputPath);
|
|
|
|
|
|
|
|
|
|
var buildOptions = BuildOptions.BuildScriptsOnly;
|
2023-05-03 17:17:40 +08:00
|
|
|
|
#if UNITY_2021_2_OR_NEWER
|
2023-03-13 12:17:39 +08:00
|
|
|
|
buildOptions |= BuildOptions.CleanBuildCache;
|
|
|
|
|
#endif
|
2022-12-16 11:03:03 +08:00
|
|
|
|
|
|
|
|
|
bool oldExportAndroidProj = EditorUserBuildSettings.exportAsGoogleAndroidProject;
|
2022-12-16 11:23:37 +08:00
|
|
|
|
#if UNITY_EDITOR_OSX
|
|
|
|
|
bool oldCreateSolution = UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject;
|
|
|
|
|
#elif UNITY_EDITOR_WIN
|
|
|
|
|
bool oldCreateSolution = UnityEditor.WindowsStandalone.UserBuildSettings.createSolution;
|
|
|
|
|
#endif
|
2022-12-16 11:03:03 +08:00
|
|
|
|
bool oldBuildScriptsOnly = EditorUserBuildSettings.buildScriptsOnly;
|
|
|
|
|
EditorUserBuildSettings.buildScriptsOnly = true;
|
|
|
|
|
|
|
|
|
|
switch (target)
|
|
|
|
|
{
|
|
|
|
|
case BuildTarget.StandaloneWindows:
|
|
|
|
|
case BuildTarget.StandaloneWindows64:
|
|
|
|
|
{
|
2022-12-16 11:23:37 +08:00
|
|
|
|
#if UNITY_EDITOR_WIN
|
2022-12-16 11:03:03 +08:00
|
|
|
|
UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = true;
|
2022-12-16 11:23:37 +08:00
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case BuildTarget.StandaloneOSX:
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR_OSX
|
|
|
|
|
UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject = true;
|
|
|
|
|
#endif
|
2022-12-16 11:03:03 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case BuildTarget.Android:
|
|
|
|
|
{
|
|
|
|
|
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
|
|
|
|
|
{
|
|
|
|
|
scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(),
|
|
|
|
|
locationPathName = GetLocationPathName(outputPath, target),
|
|
|
|
|
options = buildOptions,
|
|
|
|
|
target = target,
|
|
|
|
|
targetGroup = group,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var report = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
|
|
|
|
|
|
|
|
|
EditorUserBuildSettings.buildScriptsOnly = oldBuildScriptsOnly;
|
|
|
|
|
switch (target)
|
|
|
|
|
{
|
|
|
|
|
case BuildTarget.StandaloneWindows:
|
|
|
|
|
case BuildTarget.StandaloneWindows64:
|
2022-12-16 11:23:37 +08:00
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
|
UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = oldCreateSolution;
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case BuildTarget.StandaloneOSX:
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR_OSX
|
|
|
|
|
UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject = oldCreateSolution;
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-12-16 11:03:03 +08:00
|
|
|
|
case BuildTarget.Android:
|
|
|
|
|
{
|
|
|
|
|
EditorUserBuildSettings.exportAsGoogleAndroidProject = oldExportAndroidProj;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded)
|
|
|
|
|
{
|
2023-04-30 01:35:25 +08:00
|
|
|
|
throw new Exception("GenerateStripedAOTDlls 失败");
|
2022-12-16 11:03:03 +08:00
|
|
|
|
}
|
|
|
|
|
Debug.Log($"GenerateStripedAOTDlls target:{target} group:{group} path:{outputPath}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|