gpt4 book ai didi

unity-game-engine - 如何通过 Unity 编辑器脚本强制构建过程失败?

转载 作者:行者123 更新时间:2023-12-02 13:31:53 25 4
gpt4 key购买 nike

如果不满足某些验证条件,我想强制构建过程失败。

我尝试使用 IPreprocessBuildWithReport 但没有成功:

using UnityEditor.Build;
using UnityEditor.Build.Reporting;

public class BuildProcessor : IPreprocessBuildWithReport
{
public int callbackOrder => 0;

public void OnPreprocessBuild(BuildReport report)
{
// Attempt 1
// Does not compile because the 'BuildSummary.result' is read only
report.summary.result = BuildResult.Failed;

// Attempt 2
// Causes a log in the Unity editor, but the build still succeeds
throw new BuildFailedException("Forced fail");
}
}

有什么方法可以以编程方式强制构建过程失败吗?

我使用的是Unity 2018.3.8f1。

最佳答案

自 2019.2.14f1 起,停止构建的正确方法是抛出 BuildFailedException

其他异常类型不会中断构建。
派生异常类型不会中断构建。
记录错误肯定不会中断构建。

这就是Unity处理PostProcessPlayer中异常的方式:

try
{
postprocessor.PostProcess(args, out props);
}
catch (System.Exception e)
{
// Rethrow exceptions during build postprocessing as BuildFailedException, so we don't pretend the build was fine.
throw new UnityEditor.Build.BuildFailedException(e);
}


为了清楚起见,这不会不会停止构建。:

// This is not precisely a BuildFailedException. So the build will go on and succeed.
throw new CustomBuildFailedException();

...

public class CustomBuildFailedException: BuildException() {}

关于unity-game-engine - 如何通过 Unity 编辑器脚本强制构建过程失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55198847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com