facebook twitter hatena line email

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

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(namespaceを使う場合)
(同じ利用者による、間の4版が非表示)
行45: 行45:
 
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で開いている場合は、閉じる
  
 
===コマンドオプション===
 
===コマンドオプション===
行53: 行62:
  
 
参考:https://qiita.com/sango/items/474efb4c016a136c84ce
 
参考: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