private static void ApplyResConfig() { int sum = 1; int id = 0; EditorApplication.update = delegate() { bool isCancle = false; isCancle = EditorUtility.DisplayCancelableProgressBar("执行中...", "准备开始应用配置...", (float)id / sum); if (isCancle || id >= sum) { EditorUtility.ClearProgressBar(); EditorApplication.update = null; return; } //加载json文件 Object[] textures = GetSelectedTextures(); sum = textures.Length; foreach (Texture2D texture in textures) { isCancle = EditorUtility.DisplayCancelableProgressBar("执行中...", "应用图片配置...", (float)id / sum); if (isCancle || id >= sum) { EditorUtility.ClearProgressBar(); EditorApplication.update = null; return; } string path = AssetDatabase.GetAssetPath(texture); ResItem resItem = ResData.FetchItem(path); if (resItem == null) { Debug.LogError(path + "is not config data.."); continue; } TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter; TextureImporterSettings tis = new TextureImporterSettings(); #if UNITY_EDITOR_WIN TextureImporterPlatformSettings textureImporterSettings = textureImporter.GetPlatformTextureSettings("Android"); #elif UNITY_EDITOR_OSX TextureImporterPlatformSettings textureImporterSettings = textureImporter.GetPlatformTextureSettings("iOS"); #endif textureImporterSettings.overridden = true; textureImporter.ReadTextureSettings(tis); tis.textureType = (TextureImporterType)resItem.textureType; tis.readable = resItem.readEnable == 1 ? true: false; tis.mipmapEnabled = resItem.gengrateMipMaps == 1 ? true : false; textureImporterSettings.maxTextureSize = int.Parse(resItem.maxSize); textureImporterSettings.format = (TextureImporterFormat)resItem.format; textureImporter.SetPlatformTextureSettings(textureImporterSettings); textureImporter.SetTextureSettings(tis); AssetDatabase.ImportAsset(path); id++; } //添加声音的配置 Object[] audioclips = GetSelecetedSound(); sum += audioclips.Length; foreach (AudioClip audioclip in audioclips) { isCancle = EditorUtility.DisplayCancelableProgressBar("执行中...", "应用声音配置...", (float)id / sum); if (isCancle || id >= sum) { EditorUtility.ClearProgressBar(); EditorApplication.update = null; return; } string path = AssetDatabase.GetAssetPath(audioclip); AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter; ResItem resItem = ResData.FetchItem(path); AudioImporterSampleSettings audioImporterSampleSettings = new AudioImporterSampleSettings(); audioImporterSampleSettings.loadType = (AudioClipLoadType)resItem.loadtype; audioImporterSampleSettings.compressionFormat = (AudioCompressionFormat)resItem.compressionFormat; audioImporterSampleSettings.quality = float.Parse(resItem.quality); audioImporterSampleSettings.sampleRateSetting = (AudioSampleRateSetting)resItem.sampleRateSet; #if UNITY_EDITOR_WIN audioImporter.SetOverrideSampleSettings("Android", audioImporterSampleSettings); #elif UNITY_EDITOR_OSX audioImporter.SetOverrideSampleSettings("iOS", audioImporterSampleSettings); #endif AssetDatabase.ImportAsset(path); id++; } if (isCancle || id >= sum) { EditorUtility.ClearProgressBar(); EditorApplication.update = null; } }; }