/// <summary> /// 循环设置选择的贴图 /// </summary> private static void LoopSetTexture() { 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); TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter; #if UNITY_EDITOR_WIN TextureImporterPlatformSettings textureImporterSettings = textureImporter.GetPlatformTextureSettings("Android"); #elif UNITY_EDITOR_OSX TextureImporterPlatformSettings textureImporterSettings = textureImporter.GetPlatformTextureSettings("iOS"); #endif //TextureImporterSettings tis = new TextureImporterSettings(); // texImporter.ReadTextureSettings(tis); // texImporter.SetTextureSettings(tis); // AssetDatabase.ImportAsset(path); ResItem resItem = new ResItem(); resItem.name = textureImporter.name; resItem.path = path; resItem.resType = "texture"; resItem.textureType = (int)textureImporter.textureType; resItem.readEnable = textureImporter.isReadable == true?1:2; resItem.gengrateMipMaps = textureImporter.mipmapEnabled == true ? 1 : 2; if (textureImporterSettings.overridden) { resItem.maxSize = textureImporterSettings.maxTextureSize.ToString(); resItem.format = (int)textureImporterSettings.format; } else { resItem.maxSize = textureImporter.maxTextureSize.ToString(); resItem.format = (int)textureImporter.textureFormat; } ResData.AddRestItem(resItem); 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; #if UNITY_EDITOR_WIN AudioImporterSampleSettings audioImporterSampleSettings = audioImporter.GetOverrideSampleSettings("Android"); #elif UNITY_EDITOR_OSX AudioImporterSampleSettings audioImporterSampleSettings = audioImporter.GetOverrideSampleSettings("iOS"); #endif ResItem resItem = new ResItem(); resItem.name = audioImporter.name; resItem.path = path; resItem.resType = "audioclip"; resItem.loadtype = (int)audioImporterSampleSettings.loadType; resItem.compressionFormat = (int)audioImporterSampleSettings.compressionFormat; resItem.quality = audioImporterSampleSettings.quality.ToString(); resItem.sampleRateSet = (int)audioImporterSampleSettings.sampleRateSetting; ResData.AddRestItem(resItem); id++; } if (isCancle || id >= sum) { EditorUtility.ClearProgressBar(); EditorApplication.update = null; } ResData.Save(); }; }