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(); }
public override void CopyData(ImportData data) { TextureImportData tData = data as TextureImportData; if (tData == null) { return; } base.CopyData(data); AlphaMode = tData.AlphaMode; TexType = tData.TexType; AndroidFormat = tData.AndroidFormat; IosFormat = tData.IosFormat; ReadWriteEnable = tData.ReadWriteEnable; MipmapEnable = tData.MipmapEnable; MaxSize = tData.MaxSize; }
public override void Draw(Rect r) { int border = TableConst.TableBorder; float split = TableConst.SplitterRatio; int toolbarHeight = 80; GUILayout.BeginArea(r); GUILayout.BeginVertical(); m_control.Draw(); TextureImportData data = m_control.Data; GUILayout.BeginHorizontal(TableStyles.Toolbar); { GUILayout.Label("TextureType: ", GUILayout.Width(130)); int selType = GUILayout.SelectionGrid(data.TextureTypeIndex, TableConst.TextureType, TableConst.TextureType.Length, TableStyles.ToolbarButton); if (selType != data.TextureTypeIndex) { data.TextureTypeIndex = selType; } GUILayout.Label("TextureShape: ", GUILayout.Width(130)); int selShape = GUILayout.SelectionGrid(data.TextureShapeIndex, TableConst.TextureShape, TableConst.TextureShape.Length, TableStyles.ToolbarButton); if (selShape != data.TextureShapeIndex) { data.TextureShapeIndex = selShape; } GUILayout.Label("MaxSize: ", GUILayout.Width(60)); int preIndex = ArrayUtility.IndexOf(TableConst.MaxSizeInt, data.MaxSize); int selIndex = EditorGUILayout.Popup(preIndex, TableConst.MaxSize, TableStyles.ToolbarButton, GUILayout.MaxWidth(60)); if (selIndex != preIndex && selIndex >= 0 && selIndex < TableConst.MaxSizeInt.Length) { data.MaxSize = TableConst.MaxSizeInt[selIndex]; } bool readWriteEnable = GUILayout.Toggle(data.ReadWriteEnable, " ReadWriteEnable"); if (readWriteEnable != data.ReadWriteEnable) { data.ReadWriteEnable = readWriteEnable; } bool mipMapEnable = GUILayout.Toggle(data.MipmapEnable, " MipMapEnable"); if (mipMapEnable != data.MipmapEnable) { data.MipmapEnable = mipMapEnable; } bool preBuildEnable = GUILayout.Toggle(data.PreBuild, " PreBuildEnable"); if (preBuildEnable != data.PreBuild) { data.PreBuild = preBuildEnable; } bool forceSet = GUILayout.Toggle(data.ForceSet, " ForceSet"); if (forceSet != data.ForceSet) { data.ForceSet = forceSet; } bool alwaysMatch = GUILayout.Toggle(data.AlwaysMatch, " AlwayMatch"); if (alwaysMatch != data.AlwaysMatch) { data.AlwaysMatch = alwaysMatch; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(TableStyles.Toolbar); { GUILayout.Label("Alphamode: ", GUILayout.Width(120)); int selAlphaMode = GUILayout.SelectionGrid((int)data.AlphaMode, TableConst.AlpaMode, TableConst.AlpaMode.Length, TableStyles.ToolbarButton); if (selAlphaMode != (int)data.AlphaMode) { data.AlphaMode = (TextureAlphaMode)selAlphaMode; } GUILayout.Label("AndroidFormat: ", GUILayout.Width(120)); int selAndroidFormat = GUILayout.SelectionGrid(data.AndroidFormatIndex, TableConst.AndoridFormat, TableConst.AndoridFormat.Length, TableStyles.ToolbarButton); if (selAndroidFormat != data.AndroidFormatIndex) { data.AndroidFormatIndex = selAndroidFormat; } GUILayout.Label("IosFormat: ", GUILayout.Width(120)); int selIosFormat = GUILayout.SelectionGrid(data.IosFormatIndex, TableConst.IosFormat, TableConst.IosFormat.Length, TableStyles.ToolbarButton); if (selIosFormat != data.IosFormatIndex) { data.IosFormatIndex = selIosFormat; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(TableStyles.Toolbar); { bool showUnFormatObject = GUILayout.Toggle(m_control.UnFormat, " Show Unformat Data"); if (showUnFormatObject != m_control.UnFormat) { m_control.UnFormat = showUnFormatObject; m_control.OnDataSelectedIndex(); } if (GUILayout.Button("Move Up Priority", TableStyles.ToolbarButton, GUILayout.MaxWidth(120))) { m_control.ModifDataPriority(true); } if (GUILayout.Button("Move Down Priority", TableStyles.ToolbarButton, GUILayout.MaxWidth(120))) { m_control.ModifDataPriority(false); } if (GUILayout.Button("Apply Select Format", TableStyles.ToolbarButton, GUILayout.MaxWidth(160))) { TextureFormater.ApplyFormatToObject(m_control.SelectData); } if (GUILayout.Button("Refresh Select Data", TableStyles.ToolbarButton, GUILayout.MaxWidth(140))) { if (m_control.Index != -1) { m_control.RefreshDataByRootPath(m_control.SelectData.RootPath); } } if (GUILayout.Button("Refresh All Data", TableStyles.ToolbarButton, GUILayout.MaxWidth(140))) { m_control.RefreshBaseData(); } GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); int startY = toolbarHeight + border; int height = (int)(r.height - startY - border * 2); if (m_dataTable != null) { m_dataTable.Draw(new Rect(border, startY, r.width - 2 * border, (int)(height * split - border * 1.5f))); } if (m_showTable != null) { m_showTable.Draw(new Rect(border, (int)(height * split + border * 0.5f + startY), r.width - 2 * border, (int)(height * (1.0f - split) - border * 1.5f))); } GUILayout.EndVertical(); GUILayout.EndArea(); }
public static void FormatTexture(string path, TextureImportData data) { //AssetBundleManifest }