Unity AppIconの設定方法

4656 ワード

unity自動パッケージングツールを作成する場合、異なるチャネルには異なるAppIconが必要で、ネット上で方法を探して、記録します
Unity4.6テストが利用可能、Unity 2017.2.0テストは使用できません
コード:
    public  void SetDefaultIcon()
    {
     Texture2D texture = AssetDatabase.LoadAssetAtPath(string.Format("Assets/AppIcon/{0}.png", "appicon"), typeof(Texture2D)) as Texture2D; MethodInfo getIconFormPlatform
= typeof(PlayerSettings).GetMethod("GetIconsForPlatform", BindingFlags.NonPublic | BindingFlags.Static); MethodInfo getIconSizesForPlatform = typeof(PlayerSettings).GetMethod("GetIconSizesForPlatform", BindingFlags.NonPublic | BindingFlags.Static); MethodInfo setIconsForPlatform = typeof(PlayerSettings).GetMethod("SetIconsForPlatform", BindingFlags.NonPublic | BindingFlags.Static); Texture2D[] textureArray = (Texture2D[])getIconFormPlatform.Invoke(null, new object[] { string.Empty }); var iconSizesForPlatform = (int[])getIconSizesForPlatform.Invoke(null, new object[] { string.Empty }); if (textureArray.Length != iconSizesForPlatform.Length) { textureArray = new Texture2D[iconSizesForPlatform.Length]; setIconsForPlatform.Invoke(null, new object[] { string.Empty, textureArray }); }
     textureArray[0] = texture; setIconsForPlatform.Invoke(
null, new object[] { string.Empty, textureArray }); AssetDatabase.SaveAssets(); }

自分で模索して、2017のAPPIconの修正方法を振り出しました.
    private void _setDefaultIcon(string iconName)
    {
        Texture2D texture = AssetDatabase.LoadAssetAtPath(string.Format("Assets/Images/Icon/{0}.png", iconName),
            typeof(Texture2D)) as Texture2D;

        int[] iconSize = PlayerSettings.GetIconSizesForTargetGroup(BuildTargetGroup.Android);
        Texture2D[] textureArray = new Texture2D[iconSize.Length];
        for (int i = 0; i < textureArray.Length; i++)
        {
            textureArray[i] = texture;
        }
        textureArray[0] = texture;
        PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, textureArray);
        AssetDatabase.SaveAssets();
    }

 
転載先:https://www.cnblogs.com/Yellow0-0River/p/9208278.html