Unity UGUI图集打包Assetbundle

Ugui图集,Sprite是根据PackingTag来分图集

那么Ugui图集怎么打包Assetbundle?

只要我们把Assetbundle的标签设置为PackingTag就可以,然后打包Assetbundle,测试过drawcall不会增多

这些动态设置PackingTag和Assetbundle一般都用工具来设

我这个工具图集路径是在Assets/AssetBundleRes/atlas/

    [MenuItem("AssetBundle/一键设置atlas目录的图集(atlas下子文件夹名字作为图集名)")]
    /// <summary>
    /// 设置图片格式,设置图集assetbundleName
    /// </summary>
    static void SetSpriteAltas()
    {
        AssetDatabase.Refresh();
        DirectoryInfo thisOne = new DirectoryInfo(Application.dataPath + "/AssetBundleRes/atlas/");
        foreach (DirectoryInfo info in thisOne.GetDirectories())
        {
            string[] paths = Directory.GetFiles(info.FullName);
            for (int i = 0; i < paths.Length; i++)
            {
                bool change = false;
                string path = paths[i].Replace('\\', '/');
                if (path.Contains("meta"))
                {
                    continue;
                }
                System.Drawing.Image ri = System.Drawing.Image.FromFile(path);
                path = path.Substring(path.IndexOf("Assets/"));
                int textureSize = Math.Max(ri.Width, ri.Height);

                AssetImporter asset = AssetImporter.GetAtPath(path);
                if (null == asset) { continue; }
                if (asset.assetBundleName != info.Name)
                {
                    change = true;
                    asset.assetBundleName = info.Name; //设置Bundle文件的名称  
                }

                TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter;
                if (ti.textureType != TextureImporterType.Sprite)
                {
                    change = true;
                    ti.textureType = TextureImporterType.Sprite;
                }
                if (ti.spriteImportMode != SpriteImportMode.Single)
                {
                    change = true;
                    ti.spriteImportMode = SpriteImportMode.Single;
                }
                if (ti.mipmapEnabled != false)
                {
                    change = true;
                    ti.mipmapEnabled = false;
                }
                if (ti.spritePackingTag != info.Name)
                {
                    change = true;
                    ti.spritePackingTag = info.Name;
                }
                if (ti.maxTextureSize != 1024)
                {
                    change = true;
                    ti.maxTextureSize = 1024;
                }
                if (ti.wrapMode != TextureWrapMode.Clamp)
                {
                    change = true;
                    ti.wrapMode = TextureWrapMode.Clamp;
                }
                if(textureSize <= 16 && ti.textureCompression != TextureImporterCompression.Uncompressed)
                {
                    change = true;
                    ti.textureCompression = TextureImporterCompression.Uncompressed;
                }
                if (change)
                    asset.SaveAndReimport();
            }
        }
        AssetDatabase.Refresh();
    }

猜你喜欢

转载自blog.csdn.net/SnoopyNa2Co3/article/details/81562101