using System.Collections.Generic; using Module.Log; using UnityEditor; using UnityEngine; public class RemoveNormalCompress { private readonly List _textureImporters; private int _index; private RemoveNormalCompress() { _textureImporters = new List(); var allPaths = EditorCommonUtility.GetAllAssetPathsFromSelect(); for (var i = 0; i < allPaths.Count; i++) { var path = allPaths[i]; var importer = AssetImporter.GetAtPath(path) as TextureImporter; if (importer != null && importer.normalmap && (importer.mipmapEnabled || importer.compressionQuality < 100 || importer.textureFormat != TextureImporterFormat.ARGB32)) _textureImporters.Add(importer); } } // 丢失动画的状态,会试图修复状态;动画名称不对应动画状态,会试图修改动画名称; [MenuItem("Assets/Normal/移除法线压缩")] public static void RemovAnimatoreTransitions() { var animatorFix = new RemoveNormalCompress(); animatorFix.Start(); } private void Start() { if (_textureImporters.Count > 0) EditorApplication.update = Update; } private void Stop() { EditorUtility.ClearProgressBar(); EditorApplication.update = null; AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorUtility.UnloadUnusedAssetsImmediate(true); } private void Update() { // 每一帧处理一个State,使移动后的路径能够正常赋值 if (_index > _textureImporters.Count - 1) { LogModule.WarningLog("******** 法线压缩全部解除 ********"); Stop(); } else { var importer = _textureImporters[_index]; _index++; var cancel = EditorUtility.DisplayCancelableProgressBar("去除法线压缩", importer.assetPath, _index / (float) _textureImporters.Count); if (cancel) Stop(); else { importer.mipmapEnabled = false; importer.compressionQuality = 100; importer.textureFormat = TextureImporterFormat.ARGB32; importer.SaveAndReimport(); } } } }