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
        /// <summary>
        /// 执行生成_文件模式
        /// </summary>
        /// <param name="jsonAssets"></param>
        /// <param name="isGenerateAtlas">是否生成图集</param>
        /// <param name="isHighQuality"></param>
        /// <param name="isBuildAssetbundle"></param>
        public static void ExecuteFileMode(JsonAsset[] jsonAssets, InputParam param_)
        {
            AtlasBatchSetting.Initialize();
            AtlasQualitySetting.Initialize();
            AtlasSpritePaddingHelper.Initialize();
            PrefabGenerator.Initialize();

            for (int i = 0; i < jsonAssets.Length; i++)
            {
                if (jsonAssets[i] != null)
                {
                    ProcessJson(jsonAssets[i], param_);
                }
            }
        }