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();
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM