Unity/Editor/コマンド実行
提供: 初心者エンジニアの簡易メモ
自動ビルド対応方法
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"); } } }
コマンド実行
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が出るとき
ビルドが失敗してるので、プラットフォームが正しいかなど確認する。
Aborting batchmode due to failure: Scripts have compiler errors.