facebook twitter hatena line email

「Unity/Editor/コマンド実行」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(compiler errorsが出るとき)
行50: 行50:
  
 
===compiler errorsが出るとき===
 
===compiler errorsが出るとき===
ビルドが失敗してるので、プラットフォームが正しいかなど確認する。
+
ビルドが失敗してるので、プラットフォームが正しいかなど確認する。(GUI上での実行だと、スクリプトエラーが発生してるはず)
 
<pre>
 
<pre>
 
Aborting batchmode due to failure:
 
Aborting batchmode due to failure:
 
Scripts have compiler errors.
 
Scripts have compiler errors.
 
</pre>
 
</pre>

2021年8月3日 (火) 19:59時点における版

コマンド実行の対応方法

UnityEditorを使って、commandで実行

公式マニュアル:https://docs.unity3d.com/ja/2018.4/Manual/CommandLineArguments.html

サンプル

Assets/Editor/MyEditorScript.cs

using UnityEditor;
using UnityEngine;
using UnityEditor.Build.Reporting;
class MyEditorScript
{
    static void PerformBuild()
    {
        BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
        buildPlayerOptions.scenes = new[] { "Assets/Scenes/SampleScene.unity" };
        buildPlayerOptions.locationPathName = "WebGLBuild"; // 生成されるビルドのディレクトリ名
        buildPlayerOptions.target = BuildTarget.WebGL;
        buildPlayerOptions.options = BuildOptions.None;
        BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions);
        BuildSummary summary = report.summary;
        if (summary.result == BuildResult.Succeeded)
        {
            Debug.Log("Build succeeded: " + summary.totalSize + " bytes");
        }
        if (summary.result == BuildResult.Failed)
        {
            Debug.Log("Build failed");
        }
    }
}

上記例では、コマンド実行すると、WebGLBuildのディレクトリに、ビルドファイルが、生成される

コマンド実行

mac

/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod MyEditorScript.PerformBuild

mac(unity hub)

/Applications/Unity/Hub/Editor/2019.4.26f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod MyEditorScript.PerformBuild

project openエラーが出るとき

プロジェクトをGUIで開いているとエラーが出るので、閉じてからコマンド実行する

Aborting batchmode due to failure:
Fatal Error! It looks like another Unity instance is running with this project open.
Multiple Unity instances cannot open the same project.

compiler errorsが出るとき

ビルドが失敗してるので、プラットフォームが正しいかなど確認する。(GUI上での実行だと、スクリプトエラーが発生してるはず)

Aborting batchmode due to failure:
Scripts have compiler errors.