2025-03-11 17:46:52 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using AlicizaX.Editor;
|
2025-03-24 13:17:04 +08:00
|
|
|
|
using AlicizaX;
|
2025-03-11 17:46:52 +08:00
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public static class AppBuildHelper
|
|
|
|
|
{
|
2025-03-21 10:51:15 +08:00
|
|
|
|
public static void BuildApplication(AppBuildParameter appBuildParameter, bool showExplorer = false)
|
2025-03-11 17:46:52 +08:00
|
|
|
|
{
|
2025-03-20 14:23:00 +08:00
|
|
|
|
if (!Directory.Exists(appBuildParameter.OutPutPath))
|
2025-03-11 17:46:52 +08:00
|
|
|
|
{
|
2025-03-20 14:23:00 +08:00
|
|
|
|
Directory.CreateDirectory(appBuildParameter.OutPutPath);
|
2025-03-11 17:46:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Debug.Log("Starting build application");
|
|
|
|
|
|
2025-03-20 14:23:00 +08:00
|
|
|
|
BuilderGenerate.GeneratAppBuilderSetting(appBuildParameter.Language, appBuildParameter.ShowDebugWnd, appBuildParameter.ResMode);
|
2025-03-20 10:44:52 +08:00
|
|
|
|
|
2025-03-11 17:46:52 +08:00
|
|
|
|
Debug.Log("Generate AppBuilderSetting.bytes");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var options = new BuildPlayerOptions
|
|
|
|
|
{
|
2025-03-21 10:51:15 +08:00
|
|
|
|
scenes = appBuildParameter.Scenes,
|
2025-03-20 14:23:00 +08:00
|
|
|
|
locationPathName = Path.Combine(appBuildParameter.OutPutPath, appBuildParameter.FileName),
|
|
|
|
|
target = appBuildParameter.BuildTarget,
|
|
|
|
|
options = appBuildParameter.DevelopBuild ? BuildOptions.Development : BuildOptions.None
|
2025-03-11 17:46:52 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var report = BuildPipeline.BuildPlayer(options);
|
|
|
|
|
HandleBuildReport(report);
|
2025-03-21 10:51:15 +08:00
|
|
|
|
if (showExplorer)
|
|
|
|
|
{
|
|
|
|
|
OpenFolder.Execute(report.summary.outputPath);
|
|
|
|
|
}
|
2025-03-11 17:46:52 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"构建过程中发生异常: {e.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void HandleBuildReport(UnityEditor.Build.Reporting.BuildReport report)
|
|
|
|
|
{
|
|
|
|
|
if (report.summary.result == UnityEditor.Build.Reporting.BuildResult.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"整包构建完成:${report.summary.outputPath}");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-07-31 21:48:09 +08:00
|
|
|
|
#if UNITY_2023_1_OR_NEWER
|
|
|
|
|
Debug.LogError(report.SummarizeErrors());
|
|
|
|
|
#else
|
|
|
|
|
var errors = new List<string>();
|
|
|
|
|
foreach (var step in report.steps)
|
|
|
|
|
{
|
|
|
|
|
foreach (var msg in step.messages)
|
|
|
|
|
{
|
|
|
|
|
if (msg.type == LogType.Error || msg.type == LogType.Exception)
|
|
|
|
|
{
|
|
|
|
|
errors.Add($"[Step: {step.name}] {msg.content}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Debug.LogError($"构建失败,错误信息:\n{string.Join("\n", errors)}");
|
|
|
|
|
#endif
|
2025-03-11 17:46:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|