Ejemplo n.º 1
0
        static void GenerateAtlas()
        {
            _atlas = new Texture2D(ATLAS_MAX_SIZE, ATLAS_MAX_SIZE);
            Rect[] rects = _atlas.PackTextures(GetPackTextures(), 0, ATLAS_MAX_SIZE, false);    //pack!

            string atlasPath      = KAssetManager.GetAtlasPath(_atlasName);
            string alphaAtlasPath = KAssetManager.GetAlphaAtlasPath(_atlasName);
            string folderPath     = mg.org.FileUtility.GetFolderFromFullPath(atlasPath);

            mg.org.FileUtility.EnsureDirectory(folderPath);        //创建文件夹

            _atlas = AtlasOptimizer.Optimize(_atlas, rects, true); //优化图集
            AtlasWriter.Write(_atlas, atlasPath);                  //保存图集
            LogAtlasSize(_atlas, _atlasName);

            // 暂时不采用分开的纹理格式, 删除ALPHA贴图
            AssetDatabase.DeleteAsset(alphaAtlasPath);

            bool isTurecolor = AtlasQualitySetting.Contains(_atlasName);

            //if(isTurecolor)
            //{
            //    AssetDatabase.DeleteAsset(alphaAtlasPath);
            //}
            //else
            //{
            //    //EtcGeneratorWrapper.Execute(atlasPath, _isHighQuality);
            //    ImageChannelSpliterWrapper.Execute(atlasPath, _isHighQuality);
            //    AssetDatabase.ImportAsset(alphaAtlasPath, ImportAssetOptions.ForceUpdate);
            //    TextureImporterUtil.CreateEtcAlphaChannelImporter(alphaAtlasPath);
            //    AssetDatabase.ImportAsset(alphaAtlasPath, ImportAssetOptions.ForceUpdate);
            //}

            try
            {
                AssetDatabase.ImportAsset(atlasPath, ImportAssetOptions.ForceUpdate);
            }
            catch (System.Exception e)
            {
                Debug.Log("ImportAssetError:" + atlasPath);
            }

            isTurecolor = false;    //都用压缩格式
            TextureImporterFormat format = isTurecolor ? TextureImporterFormat.ARGB32 : TextureImporterFormat.AutomaticCompressed;

            TextureImporterUtil.CreateMultipleSpriteImporter(atlasPath, rects, GetPackTextureNames(), GetSpriteBorders(), _atlas.width, _atlas.height, format, ATLAS_MAX_SIZE);
            AssetDatabase.ImportAsset(atlasPath, ImportAssetOptions.ForceUpdate);
            //记录所有图片的边距数据
            AtlasSpritePaddingHelper.WriteSpritePaddingRecord(_uniqueTextureDataList, KAssetManager.GetAtlasSpritePaddingRecordPath(_atlasName));
            //暂时不采用分开的纹理格式

            //采用替换内置材质的方式
            //EtcMaterialCreator.CreateWithoutAlpha(EtcMaterialCreator.PSD4UGUI_ONE_TEX_SHADER, atlasPath);
        }
Ejemplo n.º 2
0
        //保存readme
        static void WriteBatchedReadme(string atlasName, string jsonName)
        {
            string path = KAssetManager.AtlasFolder + "/" + jsonName + "/readme.txt";

            if (atlasName == jsonName)
            {
                AssetDatabase.DeleteAsset(path);
                return;
            }

            AssetDatabase.DeleteAsset(KAssetManager.GetAtlasPath(jsonName));
            AssetDatabase.DeleteAsset(KAssetManager.GetAlphaAtlasPath(jsonName));
            AssetDatabase.DeleteAsset(KAssetManager.GetEtcMaterialPath(jsonName));

            //合并到别的图集,删除原来的文件夹
            KAssetManager.DeleteAtlasFolder(jsonName);

            //不导出readme了
            //string content = string.Format(BATCHED_TEMPLATE, jsonName, atlasName);
            //File.WriteAllText(Application.dataPath.Replace("Assets", "") + path, content, System.Text.Encoding.Unicode);
            //AssetDatabase.ImportAsset(path);
        }