Unity设置AppIcon方法

制作unity自动打包工具时,不同的渠道需要不同的AppIcon,在网上找了方法,记录下

Unity4.6测试可用,Unity2017.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();
    }
复制代码

 

posted @   JohnRey  阅读(5843)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示