自动设置图片纹理格式
1,选择文件路径
Path.AltDirectorySeparatorChar 替换目录分隔符
Path.DirectorySeparatorChar 目录分隔符
默认字符用于分隔目录层次。(只读)
This is ‘\’ on Windows and ‘/’ on Mac OS X
Windows用”\”,Mac OS用”/”
2,使用AssetPostprocessor类
AssetPostprocessor 是一个编辑器类,一个资源导入的一个管理器,在资源导入之前和之后可以根据导入的资源做一些设置和一些数据的修改,比如网格,纹理的压缩,模型添加组件等。
具体可以参考 这个http://blog.youkuaiyun.com/yhy2218/article/details/50847127
借鉴大神的代码总结到此
void OnPreprocessTexture()
{
string sep = Path.DirectorySeparatorChar.ToString();
string mapTextureDir = "Assets" + sep + "Textures" + sep + "Map" + sep;
if (assetPath.IndexOf(mapTextureDir) == 0)
{
TextureImporter importer = AssetImporter.GetAtPath(assetPath) as TextureImporter;
importer.textureType = TextureImporterType.Advanced;
importer.npotScale = TextureImporterNPOTScale.ToNearest;
importer.generateCubemap = TextureImporterGenerateCubemap.None;
importer.isReadable = false;
importer.grayscaleToAlpha = false;
importer.alphaIsTransparency = false;
importer.linearTexture = true;
importer.mipmapEnabled = false;
importer.wrapMode = TextureWrapMode.Clamp;
importer.filterMode = FilterMode.Bilinear;
importer.anisoLevel = 0;
importer.maxTextureSize = 512;
importer.textureFormat = TextureImporterFormat.AutomaticCompressed;
importer.SetPlatformTextureSettings("iPhone", 512, TextureImporterFormat.PVRTC_RGB4, 100);
importer.SetPlatformTextureSettings("Android", 512, TextureImporterFormat.ETC_RGB4, 100);
}
}
添加进度条 EditorUtility.DisplayProgressBar
EditorUtility.DisplayProgressBar(“addData”, prefabs[i], (float)i / (float)len);
EditorUtility.ClearProgressBar();
修改 Prefab 内容
PrefabUtility