本文主要是介绍UnityEditor动态生成图集SpriteAtlas,并包含文件夹图片,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
UnityEditor动态生成图集SpriteAtlas,并包含文件夹图片
//首先读取json
[MenuItem("工具/创建Atlas")]
static void AtlasCreate()
{string rpath = "Assets/AssetAll/ps";DirectoryInfo direction = new DirectoryInfo(rpath);DirectoryInfo[] directs = direction.GetDirectories();//文件夹DirectoryInfo dir;int i, j;for (i = 0; i < directs.Length; i++){dir = directs[i];string dataPath = dir.FullName;= System.IO.Path.GetFullPath(".");//创建图集string atlas = dataPath + "\\" + dir.Name + ".spriteatlas";if (File.Exists(atlas)){Debug.Log("图集找到" + atlas);}else{SpriteAtlas sa = new SpriteAtlas();SpriteAtlasPackingSettings packSet = new SpriteAtlasPackingSettings(){blockOffset = 1,enableRotation = false,enableTightPacking = false,padding = 4,};sa.SetPackingSettings(packSet);SpriteAtlasTextureSettings textureSet = new SpriteAtlasTextureSettings(){readable = true,generateMipMaps = false,sRGB = true,filterMode = FilterMode.Bilinear,};sa.SetTextureSettings(textureSet);atlas = rpath + "/" + dir.Name + "/" + dir.Name + ".spriteatlas";AssetDatabase.CreateAsset(sa, atlas);//图片的文件夹加入图集。Object texture = AssetDatabase.LoadMainAssetAtPath(rpath + "/" + dir.Name);SpriteAtlasExtensions.Add(sa, new Object[] { texture });AssetDatabase.SaveAssets();Debug.Log("图集创建:" + atlas);//设置预设名称AssetImporter atlasAssetImporter = AssetImporter.GetAtPath(atlas); //得到AssetatlasAssetImporter.assetBundleName = dir.Name;atlasAssetImporter.assetBundleVariant = "ps";}}
}
这篇关于UnityEditor动态生成图集SpriteAtlas,并包含文件夹图片的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!