Version: 2023.1

BuildReport

class in UnityEditor.Build.Reporting

/

继承自:Object

切换到手册

描述

BuildReport API 可为您提供有关 Unity 构建过程的信息。

BuildReport 对象由 BuildPipeline.BuildPlayer 返回,并且可用于发现有关文件输出、采取的构建步骤,以及本机代码剥离等其他特定于平台的信息。

For AssetBundle builds the BuildReport is available by calling GetLatestReport immediately after calling BuildPipeline.BuildAssetBundles.

                    
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;

public class BuildReportExample { [MenuItem("Example/Build AssetBundle")] static public void BuildBundles() { string buildOutputDirectory = "BuildOutput"; if (!Directory.Exists(buildOutputDirectory)) Directory.CreateDirectory(buildOutputDirectory);

var bundleDefinitions = new AssetBundleBuild[] { new AssetBundleBuild() { assetBundleName = "MyBundle", assetNames = new string[] { "Assets/Scenes/SampleScene.unity" } } };

BuildPipeline.BuildAssetBundles( buildOutputDirectory, bundleDefinitions, BuildAssetBundleOptions.ForceRebuildAssetBundle, EditorUserBuildSettings.activeBuildTarget);

BuildReport report = BuildReport.GetLatestReport(); if (report != null) { var sb = new StringBuilder(); sb.AppendLine("Build result : " + report.summary.result); sb.AppendLine("Build size : " + report.summary.totalSize + " bytes"); sb.AppendLine("Build time : " + report.summary.totalTime); sb.AppendLine("Error summary : " + report.SummarizeErrors()); sb.Append(LogBuildReportSteps(report)); sb.AppendLine(LogBuildMessages(report)); Debug.Log(sb.ToString()); } else { // Certain errors like invalid input can fail the build immediately, with no BuildReport written Debug.Log("AssetBundle build failed"); } }

public static string LogBuildReportSteps(BuildReport buildReport) { var sb = new StringBuilder();

sb.AppendLine($"Build steps: {buildReport.steps.Length}"); int maxWidth = buildReport.steps.Max(s => s.name.Length + s.depth) + 3; foreach (var step in buildReport.steps) { string rawStepOutput = new string('-', step.depth + 1) + ' ' + step.name; sb.AppendLine($"{rawStepOutput.PadRight(maxWidth)}: {step.duration:g}"); } return sb.ToString(); }

public static string LogBuildMessages(BuildReport buildReport) { var sb = new StringBuilder(); foreach (var step in buildReport.steps) { foreach (var message in step.messages) // If desired, this logic could ignore any Info or Warning messages to focus on more serious messages sb.AppendLine($"[{message.type}] {message.content}"); }

string messages = sb.ToString(); if (messages.Length > 0) return "Messages logged during Build:\n" + messages; else return ""; } }

// For the purpose of demonstration, this callback logs different types of errors and forces a build failure [BuildCallbackVersion(1)] class MyTroublesomeBuildCallback : IProcessSceneWithReport { public int callbackOrder { get { return 0; } } public void OnProcessScene(UnityEngine.SceneManagement.Scene scene, BuildReport report) { Debug.Log("MyTroublesomeBuildCallback called for " + scene.name); Debug.LogError("Logging an error");

throw new BuildFailedException("Forcing the build to stop"); } }

变量

packedAssets构建过程生成的所有 PackedAssets 的数组。
scenesUsingAssetsAn optional array of ScenesUsingAssets generated by the build process if BuildOptions.DetailedBuildReport was used during the build.
steps构建过程中发生的所有 BuildStep 的数组。
strippingInfo用于构建的 StrippingInfo 对象。
summary BuildSummary 包含关于构建过程的总体统计信息和数据。

公共函数

GetFilesReturns an array of all the files output by the build process.
SummarizeErrorsReturns a string summarizing any errors that occurred during the build

静态函数

GetLatestReportReturn the build report generated by the most recent Player or AssetBundle build

继承的成员

变量

hideFlags该对象应该隐藏、随场景一起保存还是由用户修改?
name对象的名称。

公共函数

GetInstanceIDGets the instance ID of the object.
ToString返回对象的名称。

静态函数

Destroy移除 GameObject、组件或资源。
DestroyImmediate立即销毁对象 /obj/。强烈建议您改用 Destroy。
DontDestroyOnLoad在加载新的 Scene 时,请勿销毁 Object。
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
Instantiate克隆 original 对象并返回克隆对象。

运算符

bool该对象是否存在?
operator !=比较两个对象是否引用不同的对象。
operator ==比较两个对象引用,判断它们是否引用同一个对象。