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); }
/// <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_); } } }
protected virtual void AddImageComponent(GameObject go, JsonData stateData) { KImage image = null; if (HasParam(stateData, NO_TEX) == true) //纯色 { image = go.AddComponent <KImageNoTex>(); image.type = Image.Type.Simple; } else if (HasParam(stateData, PATTERN_SCALE_9_GRID) == true) //九宫格 { image = AddScale9GridImage(go); } else if (HasParam(stateData, PATTERN_UV) == true) //渐变 { image = AddUvImage(go, stateData); } else { image = go.AddComponent <KImage>(); image.type = Image.Type.Simple; } string link = (string)stateData["link"]; //资源路径 if (HasParam(stateData, NO_TEX) == false) { image.sprite = KAssetManager.GetSprite(link); //if (LinkTextureData.GetAtlasName(link) != image.sprite.texture.name) //引用其他part的图片,暂时不需要 //{ // link = image.sprite.texture.name + "." + LinkTextureData.GetTextureName(link); // link = link.Replace("UI_", ""); //} image.spritePadding = AtlasSpritePaddingHelper.GetAtlasSpritePadding(link); } if (go.name.Contains(SHARED_ANCHOR) || link.Contains(SHARED_ANCHOR)) { //icon用 image.color = new Color(1.0f, 1.0f, 1.0f, 1.0f); var sc = GetSolidFillColor(stateData); var blendMode = GetSolidFillMode(stateData); if (blendMode == "normal") { image.overlayColor = sc; } else if (blendMode == "multiply") { image.color = sc; image.overlayColor = new Color(1.0f, 1.0f, 1.0f, 0.0f); } } else if (HasParam(stateData, NO_TEX)) { //纯色 image.sprite = null; //image.material = KAssetManager.GetNoTexMaterial(); image.color = GetSolidFillColor(stateData); //配置颜色 if (GetAlpha(stateData) > 0.03) { var comNoTex = (KImageNoTex)image; comNoTex.NeedColor = true; } } else { //image.material = KAssetManager.GetEtcMaterialByLink(link); //设置为ui对应的材质球 var sc = GetSolidFillColor(stateData); var blendMode = GetSolidFillMode(stateData); if (blendMode == "normal") { image.overlayColor = sc; } else if (blendMode == "multiply") { image.color = sc; image.overlayColor = new Color(1.0f, 1.0f, 1.0f, 0.0f); } //image.color = new Color(1.0f, 1.0f, 1.0f, 0.0f); } image.alpha = GetAlpha(stateData); //透明度 image.rotation = GetRotation(stateData); //ImageType为Simple时 image.Initialize(); }