2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Unity6 の batchmode で BuildProfile を切り替えてビルドする

Posted at

先日こちらの記事で書いた通り、
Unity6から同じプラットフォームでもBuildProfileを複数用意して、ビルド時の設定を簡単に切り替えられるようになっていました。

JenkinsなどCIツールで batchmode でビルドする際に BuildProfile を切り替えられると便利そうなので、そのサンプルです。

ビルド用のプログラム準備

Assets/Editor/Build.cs
using UnityEngine;
using UnityEditor;
using UnityEditor.Build.Profile;

public class Build {
	[MenuItem("Appli/Build")]
	public static void Execute() {
		// コマンドライン引数からBuildProfle名を取得
		string buildProfileName = GetBuildProfileName();

		// BuildProfileを読み込み
		string profilePath = $"Assets/Settings/Build Profiles/{buildProfileName}.asset";
		BuildProfile buildProfile = AssetDatabase.LoadAssetAtPath<BuildProfile>(profilePath);

		// ビルドオプション設定
		BuildPlayerWithProfileOptions buildPlayerWithProfileOptions = new BuildPlayerWithProfileOptions {
			buildProfile = buildProfile,
			locationPathName = "Build/iOS"
		};

		// アプリビルド実行
		BuildPipeline.BuildPlayer(buildPlayerWithProfileOptions);
	}

	/// <summary>
	/// コマンドライン引数から-buildProfileオプションを取得
	/// </summary>
	private static string GetBuildProfileName() {
		string[] args = System.Environment.GetCommandLineArgs();
		string buildProfile = null;

		for (int i = 0; i < args.Length; i++) {
			if (args[i] == "-buildProfile" && i + 1 < args.Length) {
				buildProfile = args[i + 1];
				break;
			}
		}

		if (string.IsNullOrEmpty(buildProfile)) {
			Debug.LogError("Build profile is not specified.");
		}

		return buildProfile;
	}
}

batchmodeでビルド実行

実行コマンド例

/Applications/Unity/Hub/Editor/6000.0.10f1/Unity.app/Contents/MacOS/Unity -quit -projectPath /Users/username/Unity/Unity_6_test -batchmode -executeMethod Build.Execute -buildProfile "iOS Profile Production"

-buildProfile "iOS Profile Production" の部分で使用するBuildProfileを指定

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?