欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

Unity设置AppIcon方法

发布时间:2025/5/22 编程问答 37 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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();}

 

转载于:https://www.cnblogs.com/Yellow0-0River/p/9208278.html

《新程序员》:云原生和全面数字化实践50位技术专家共同创作,文字、视频、音频交互阅读

总结

以上是生活随笔为你收集整理的Unity设置AppIcon方法的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。