facebook twitter hatena line email

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

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(namespaceを使う場合)
(同じ利用者による、間の24版が非表示)
行1: 行1:
==自動ビルド対応方法==
+
==コマンド実行の対応方法==
 
UnityEditorを使って、commandで実行
 
UnityEditorを使って、commandで実行
  
公式マニュアル:https://docs.unity3d.com/ja/2018.4/Manual/CommandLineArguments.html
+
公式マニュアル:https://docs.unity3d.com/ja/2019.4/Manual/CommandLineArguments.html
  
 
==サンプル==
 
==サンプル==
Assets/Editor/MyEditorScript.cs
+
Assets/Scripts/Editor/MyEditorScript.cs
 
<pre>
 
<pre>
 
using UnityEditor;
 
using UnityEditor;
 
using UnityEngine;
 
using UnityEngine;
using UnityEditor.Build.Reporting;
 
 
class MyEditorScript
 
class MyEditorScript
 
{
 
{
     static void PerformBuild()
+
     static void Exec()
 
     {
 
     {
         BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
+
         Debug.Log("Build Start");
        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");
+
        }
+
 
     }
 
     }
 
}
 
}
行35: 行20:
 
==コマンド実行==
 
==コマンド実行==
 
mac
 
mac
  /Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod MyEditorScript.PerformBuild
+
  /Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod MyEditorScript.Exec
 
mac(unity hub)
 
mac(unity hub)
  /Applications/Unity/Hub/Editor/2019.4.26f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod MyEditorScript.PerformBuild
+
  /Applications/Unity/Hub/Editor/2019.4.26f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod MyEditorScript.Exec
 +
 
 +
参考:https://docs.unity3d.com/ja/2019.4/Manual/CommandLineArguments.html
 +
 
 +
===ログ===
 +
mac
 +
~/Library/Logs/Unity/Editor.log
 +
注意:ログは、新規作成されるので、tail -f などで、確認する場合は、実行後に、tail実行しないと、確認できない。
  
 
===project openエラーが出るとき===
 
===project openエラーが出るとき===
行48: 行40:
  
 
===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>
 +
 +
===could not be found.が出る場合===
 +
以下エラーが出る場合
 +
<pre>
 +
Aborting batchmode due to failure:
 +
executeMethod method 'HogeMethod1' in class 'HogeClass1' could not be found.
 +
Argument was -executeMethod HogeMethod1.HogeClass1
 +
</pre>
 +
プロジェクトをGUIで開いている場合は、閉じる
 +
 +
===コマンドオプション===
 +
*-logFile:ログファイル
 +
*-projectPath:プロジェクトの場所
 +
*-quit:処理後自動終了
 +
Unity -batchmode -quit -logFile /tmp/build.log -projectPath ~/unity/project1 -executeMethod MyEditorScript.Exec
 +
 +
参考:https://qiita.com/sango/items/474efb4c016a136c84ce
 +
 +
===namespaceを使う場合===
 +
<pre>
 +
using UnityEditor;
 +
using UnityEngine;
 +
namespace Module1 {
 +
    class MyEditorScript
 +
    {
 +
        static void Exec()
 +
        {
 +
            Debug.Log("Build Start");
 +
        }
 +
    }
 +
}
 +
</pre>
 +
以下でコマンド実行できる
 +
/Applications/Unity/Hub/Editor/2019.4.26f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod Module1.MyEditorScript.Exec

2021年8月10日 (火) 16:34時点における版

コマンド実行の対応方法

UnityEditorを使って、commandで実行

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

サンプル

Assets/Scripts/Editor/MyEditorScript.cs

using UnityEditor;
using UnityEngine;
class MyEditorScript
{
    static void Exec()
    {
        Debug.Log("Build Start");
    }
}

コマンド実行

mac

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

mac(unity hub)

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

参考:https://docs.unity3d.com/ja/2019.4/Manual/CommandLineArguments.html

ログ

mac

~/Library/Logs/Unity/Editor.log

注意:ログは、新規作成されるので、tail -f などで、確認する場合は、実行後に、tail実行しないと、確認できない。

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.

could not be found.が出る場合

以下エラーが出る場合

Aborting batchmode due to failure:
executeMethod method 'HogeMethod1' in class 'HogeClass1' could not be found.
Argument was -executeMethod HogeMethod1.HogeClass1

プロジェクトをGUIで開いている場合は、閉じる

コマンドオプション

  • -logFile:ログファイル
  • -projectPath:プロジェクトの場所
  • -quit:処理後自動終了
Unity -batchmode -quit -logFile /tmp/build.log -projectPath ~/unity/project1 -executeMethod MyEditorScript.Exec

参考:https://qiita.com/sango/items/474efb4c016a136c84ce

namespaceを使う場合

using UnityEditor;
using UnityEngine;
namespace Module1 {
    class MyEditorScript
    {
        static void Exec()
        {
            Debug.Log("Build Start");
        }
    }
}

以下でコマンド実行できる

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