Exemple #1
0
        /// <summary>
        /// 处理所有散图
        /// </summary>
        static void ProcessTextureDataList()
        {
            foreach (LinkTextureData textureData in _uniqueTextureDataList)
            {
                string texturePath = KAssetManager.GetTexturePath(textureData.link);    //散图在Assets下的路径(External模式下是用mklink超链过来)
                //string texturePath = KAssetManager.EnsureTextureInAssets(textureData.link);

                TextureImporterUtil.CreateReadableTextureImporter(texturePath);         //处理散图
                AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate); //重新import一次

                Texture2D texture = KAssetManager.GetTextureInAssets(textureData.link); //获取图片资源
                if (textureData.IsScale9Grid == true)
                {
                    //根据九宫格生成图片的最小尺寸
                    texture = Scale9GridTextureProcessor.Process(texture, textureData.top, textureData.right, textureData.bottom, textureData.left);
                }

                Rect    rect;
                Vector4 padding;
                texture                   = TextureAlphaKicker.Kick(texture, out rect, out padding); //优化掉四周的透明像素,减少图片尺寸
                texture                   = TextureClamper.Clamp(texture);                           //四周补2像素
                textureData.texture       = texture;
                textureData.spritePadding = padding;
            }
        }
Exemple #2
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);
        }