using System; using System.Collections.Generic; using System.IO; using System.Linq; using AlicizaX.Editor; using AlicizaX; using UnityEditor; using UnityEngine; public static class AppBuildHelper { public static void BuildApplication(AppBuildParameter appBuildParameter, bool showExplorer = false) { if (!Directory.Exists(appBuildParameter.OutPutPath)) { Directory.CreateDirectory(appBuildParameter.OutPutPath); } Debug.Log("Starting build application"); BuilderGenerate.GeneratAppBuilderSetting(appBuildParameter.Language, appBuildParameter.ShowDebugWnd, appBuildParameter.ResMode); Debug.Log("Generate AppBuilderSetting.bytes"); try { var options = new BuildPlayerOptions { scenes = appBuildParameter.Scenes, locationPathName = Path.Combine(appBuildParameter.OutPutPath, appBuildParameter.FileName), target = appBuildParameter.BuildTarget, options = appBuildParameter.DevelopBuild ? BuildOptions.Development : BuildOptions.None }; var report = BuildPipeline.BuildPlayer(options); HandleBuildReport(report); if (showExplorer) { OpenFolder.Execute(report.summary.outputPath); } } 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 { #if UNITY_2023_1_OR_NEWER Debug.LogError(report.SummarizeErrors()); #else var errors = new List(); 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 } } }