「Unity/Editor/コマンド実行」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→サンプル) |
|||
行8: | 行8: | ||
<pre> | <pre> | ||
using UnityEditor; | using UnityEditor; | ||
+ | using UnityEngine; | ||
+ | using UnityEditor.Build.Reporting; | ||
class MyEditorScript | class MyEditorScript | ||
{ | { | ||
static void PerformBuild() | static void PerformBuild() | ||
{ | { | ||
− | + | BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions(); | |
− | BuildPipeline.BuildPlayer( | + | 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"); | ||
+ | } | ||
} | } | ||
} | } |
2021年8月3日 (火) 17:44時点における版
自動ビルド対応方法
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.