public static void ApplyFormatToObject(TextureImportData data) { List <object> unFortmatObject = data.GetObjects(true); for (int i = 0; i < unFortmatObject.Count; ++i) { TextureInfo texInfo = unFortmatObject[i] as TextureInfo; string name = System.IO.Path.GetFileName(texInfo.Path); if (EditorUtility.DisplayCancelableProgressBar("设置贴图格式", name, (i * 1.0f) / unFortmatObject.Count)) { Debug.LogWarning("ApplyFormatTextureObject Stop."); break; } if (texInfo == null) { continue; } TextureImporter tImporter = AssetImporter.GetAtPath(texInfo.Path) as TextureImporter; if (tImporter == null) { continue; } if (tImporter.textureType != data.TexType) { tImporter.textureType = data.TexType; } tImporter.isReadable = data.ReadWriteEnable; tImporter.mipmapEnabled = data.MipmapEnable; if (data.MaxSize > 0) { tImporter.maxTextureSize = data.MaxSize; } TextureImporterPlatformSettings settingAndroid = tImporter.GetPlatformTextureSettings(EditorConst.PlatformAndroid); settingAndroid.overridden = true; settingAndroid.format = data.GetFormatByAlphaMode(data.AndroidFormat, tImporter); settingAndroid.maxTextureSize = tImporter.maxTextureSize; tImporter.SetPlatformTextureSettings(settingAndroid); TextureImporterPlatformSettings settingIos = tImporter.GetPlatformTextureSettings(EditorConst.PlatformIos); settingIos.overridden = true; settingIos.format = data.GetFormatByAlphaMode(data.IosFormat, tImporter); settingIos.maxTextureSize = tImporter.maxTextureSize; tImporter.SetPlatformTextureSettings(settingIos); tImporter.SaveAndReimport(); } EditorUtility.ClearProgressBar(); for (int i = 0; i < unFortmatObject.Count; ++i) { TextureInfo texInfo = unFortmatObject[i] as TextureInfo; string name = System.IO.Path.GetFileName(texInfo.Path); EditorUtility.DisplayProgressBar("更新贴图数据", name, (i * 1.0f) / unFortmatObject.Count); TextureInfo.CreateTextureInfo(texInfo.Path); } EditorUtility.ClearProgressBar(); }
protected override void _RefreshList(List <string> list) { m_texInfoList = new List <TextureInfo>(); for (int i = 0; i < list.Count; ++i) { string path = EditorPath.FormatAssetPath(list[i]); string name = System.IO.Path.GetFileName(path); EditorUtility.DisplayProgressBar("获取贴图数据", name, (i * 1.0f) / list.Count); if (!EditorPath.IsTexture(path)) { continue; } TextureInfo texInfo = TextureInfo.CreateTextureInfo(path); if (texInfo != null) { m_texInfoList.Add(texInfo); } } EditorUtility.ClearProgressBar(); RefreshDataWithSelect(); }