LoginSignup
1
1

UnityでAndroidのアプリをビルドする際にアイコンを漏れなく設定しておくコード

Last updated at Posted at 2024-04-03

Androidアプリのアイコンは通常のアイコン、AdaptiveIcon,Roundアイコンと何故か3種類もあります。

それなりの規模のPJだと基本的にBatchModeでビルド関数叩いて、その際に引数で環境情報とか何某を入れるみたいな実装をすると思います。
そんなときにコード側でアイコンを変えるのが普通に面倒&忘れがちだったので備忘も兼ねて残しておきます。

環境

  • Unity2021.3.36f1

コード

build.cs
//まずはAdaptiveとRound以外を設定
var icons = PlayerSettings.GetIconsForTargetGroup(BuildTargetGroup.Android);
for (var i = 0; i < icons.Length; i++)
{
    icons[i] = 標準のアイコンTexture;
}
//標準のアイコンを反映
PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, icons);

//続いてAdaptive
var adaptive = PlayerSettings.GetPlatformIcons(BuildTargetGroup.Android,
    UnityEditor.Android.AndroidPlatformIconKind.Adaptive);

for (var i = 0; i < adaptive.Length; i++)
{
    adaptive[i].SetTexture(AdaptiveIconの背景レイヤー画像, 0);
    adaptive[i].SetTexture(AdaptiveIconの前面レイヤー画像, 1);
}
//Adaptiveを判定
PlayerSettings.SetPlatformIcons(BuildTargetGroup.Android, UnityEditor.Android.AndroidPlatformIconKind.Adaptive, adaptive);

//Roundアイコン
var round = PlayerSettings.GetPlatformIcons(BuildTargetGroup.Android,
    UnityEditor.Android.AndroidPlatformIconKind.Round);
for (int i = 0; i < round.Length; i++)
{
    round[i].SetTexture(Round用のアイコン画像);
}
PlayerSettings.SetPlatformIcons(BuildTargetGroup.Android, UnityEditor.Android.AndroidPlatformIconKind.Round, round);

これできっと大丈夫!

1
1
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
1
1