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
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"错误信息: {report.SummarizeErrors()}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|