【Unity6】Macでビルドしたものを実行した際にGameMode通知が出るのに対応する

Unity6.2(6000.2.7f2), MacOS Sequoia 15.6で動作を確認しています

問題

Macでビルドしたアプリケーションを実行した際に
以下のような通知が出てくることがあります

これはmacOSSequoia(15.0以降)で導入されたGameMode機能を使用するということですね
Unityを使ってゲームを作っているのであれば
パフォーマンスが優先されるのでとても助かる機能であるかと思います。

しかし
デスクトップ常駐型のゲームなどを作っている場合にも
パフォーマンスが優先されてしまうと困る場合があるかと思います。

原因

そもそもGameModeの判定をどこで行っているのかということですが
ビルド後のアプリケーションのplistの中に

LSApplicationCategoryType
public.app-category.games

のような記述がありそこで判定していることが予測できます。
xcodeでplistを開くと他のカテゴリなども見ることができますね。

対応策

UnityのPostProcessでビルド後にplistを書き換えて対応します。
メソッドのみを切り出し示します。


/// <summary>
/// plistを編集してCategoryをgamesからutilitiesに変更し、MacOSのGame Mode通知を無効化する
/// </summary>
/// <param name="report"></param>
private void DisableMacOSGameModeNotification(BuildReport report)
{
	if (report.summary.platform != BuildTarget.StandaloneOSX)
	{
		return;
	}

	string pathToBuiltProject = report.summary.outputPath;
	string plistPath = Path.Combine(pathToBuiltProject, "Contents", "Info.plist");

	if (File.Exists(plistPath))
	{
		string plistContent = File.ReadAllText(plistPath);
		bool modified = false;

		// Unity側で書き込まれる
		// public.app-category.games を別のカテゴリに置き換え
		if (plistContent.Contains("public.app-category.games"))
		{
			plistContent = plistContent.Replace(
				"public.app-category.games",
				"public.app-category.utilities"
			);
			modified = true;
			Debug.Log("Info.plist updated: Changed category from games to utilities");
		}
		else if (!plistContent.Contains("LSApplicationCategoryType"))
		{
			// カテゴリが存在しない場合は追加
			int lastDictIndex = plistContent.LastIndexOf("</dict>");
			if (lastDictIndex > 0)
			{
				string insertion = "\t<key>LSApplicationCategoryType</key>\n\t<string>public.app-category.utilities</string>\n";
				plistContent = plistContent.Insert(lastDictIndex, insertion);
				modified = true;
				Debug.Log("Info.plist updated: Added utilities category");
			}
		}
		else
		{
			Debug.Log("LSApplicationCategoryType already set to non-games category");
		}

		if (modified)
		{
			File.WriteAllText(plistPath, plistContent);
			Debug.Log("Info.plist file saved successfully");
		}
	}
	else
	{
		Debug.LogError($"Info.plist not found at: {plistPath}");
	}
}

このコードをIPostprocessBuildWithReportを継承したクラスの
OnPostprocessBuildで呼べば動作します。

今回は便宜上utilitiesにしていますが
Game以外であれば多分GameModeにはならないかと思います。