public static void ApplyRulesToAudioClip(AudioImporter audioClipImporter, AudioClipImportRule.AudioClipImportData data) { if (null == audioClipImporter) { return; } audioClipImporter.forceToMono = data.IsForceToMono; audioClipImporter.loadInBackground = data.IsLoadInBackground; audioClipImporter.ambisonic = data.IsAmbisonic; audioClipImporter.preloadAudioData = data.IsPreloadAudioClip; AudioImporterSampleSettings settingAndroid = audioClipImporter.GetOverrideSampleSettings("Android"); settingAndroid.compressionFormat = data.AndroidCompressionFormat; settingAndroid.loadType = data.AndroidAudioClipLoadType; settingAndroid.quality = data.Quality; audioClipImporter.SetOverrideSampleSettings("Android", settingAndroid); AudioImporterSampleSettings iPhoneAndroid = audioClipImporter.GetOverrideSampleSettings("iOS"); iPhoneAndroid.compressionFormat = data.AndroidCompressionFormat; iPhoneAndroid.loadType = data.AndroidAudioClipLoadType; iPhoneAndroid.quality = data.Quality; audioClipImporter.SetOverrideSampleSettings("iOS", iPhoneAndroid); audioClipImporter.SaveAndReimport(); }
/// <summary> /// 复制音频导入器 /// </summary> public static void CopyAudioImporter(AudioImporter targetImporter, AudioImporter templateImporter) { // 通用属性 targetImporter.forceToMono = templateImporter.forceToMono; targetImporter.loadInBackground = templateImporter.loadInBackground; targetImporter.ambisonic = templateImporter.ambisonic; targetImporter.defaultSampleSettings = templateImporter.defaultSampleSettings; // 注意:Normalize没有暴露的接口 var templateObject = new SerializedObject(templateImporter); var templateProperty = templateObject.FindProperty("m_Normalize"); var targetObject = new SerializedObject(targetImporter); var targetProperty = targetObject.FindProperty("m_Normalize"); targetProperty.boolValue = templateProperty.boolValue; targetObject.ApplyModifiedProperties(); // 平台设置 AudioImporterSampleSettings sampleSettingsPC = templateImporter.GetOverrideSampleSettings("Standalone"); AudioImporterSampleSettings sampleSettingsIOS = templateImporter.GetOverrideSampleSettings("iOS"); AudioImporterSampleSettings sampleSettingsAndroid = templateImporter.GetOverrideSampleSettings("Android"); targetImporter.SetOverrideSampleSettings("Standalone", sampleSettingsPC); targetImporter.SetOverrideSampleSettings("iOS", sampleSettingsIOS); targetImporter.SetOverrideSampleSettings("Android", sampleSettingsAndroid); }
private void OnPostprocessAudio(AudioClip audioClip) { AudioImporter audioImporter = assetImporter as AudioImporter; string path = audioImporter.assetPath; if (!path.Contains(AUDIOCLIP_FOLDER)) { return; } //AudioClips/以降のパスを切り出し// path = path.Substring(path.IndexOf(AUDIOCLIP_FOLDER) + AUDIOCLIP_FOLDER.Length); //SE系は全部モノラル化// audioImporter.forceToMono = path.Contains(MENUSE) || path.Contains(GAMESE); //BGMは全部バックグラウンド読み込み// audioImporter.loadInBackground = path.Contains(BGM); //Defaultの設定// AudioImporterSampleSettings defaultSettings = audioImporter.defaultSampleSettings; if (path.Contains(BGM) || path.Contains(VOICE)) { //BGMまたはボイスならストリーミング再生// defaultSettings.loadType = AudioClipLoadType.Streaming; } else { //それ以外はメモリ内圧縮// defaultSettings.loadType = AudioClipLoadType.CompressedInMemory; //Androidの圧縮設定(再生レイテンシーのためにメモリに展開するという想定)// AudioImporterSampleSettings androidSettings = audioImporter.GetOverrideSampleSettings(PLATFORM_Android); androidSettings.loadType = AudioClipLoadType.DecompressOnLoad; audioImporter.SetOverrideSampleSettings(PLATFORM_Android, androidSettings); } //圧縮設定// defaultSettings.compressionFormat = AudioCompressionFormat.Vorbis; defaultSettings.quality = 0.2f; audioImporter.defaultSampleSettings = defaultSettings; //PC、Macのは圧縮率を低めに(ファイル容量に余裕があるという想定)// AudioImporterSampleSettings standaloneSettings = audioImporter.GetOverrideSampleSettings(PLATFORM_Standalone); standaloneSettings.quality = 0.8f; audioImporter.SetOverrideSampleSettings(PLATFORM_Standalone, standaloneSettings); }
private void OverwriteImportSettings(AudioImporter target, AudioImporter reference) { target.defaultSampleSettings = reference.defaultSampleSettings; target.forceToMono = reference.forceToMono; target.preloadAudioData = reference.preloadAudioData; foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups) { var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g, BuildTargetUtility.PlatformNameType.AudioImporter); if (reference.ContainsSampleSettingsOverride(platformName)) { var setting = reference.GetOverrideSampleSettings(platformName); if (!target.SetOverrideSampleSettings(platformName, setting)) { LogUtility.Logger.LogError("AudioImporter", string.Format("Failed to set override setting for {0}: {1}", platformName, target.assetPath)); } } else { target.ClearSampleSettingOverride(platformName); } } target.loadInBackground = reference.loadInBackground; target.ambisonic = reference.ambisonic; }
private void ReportAudio(StringBuilder sb, AudioImporter importer) { /// common sb.Append("{"); AssetsReporterUtils.AddJsonObject(sb, "path", importer.assetPath).Append(","); AssetsReporterUtils.AddJsonObject(sb, "forceToMono", importer.forceToMono).Append(","); AssetsReporterUtils.AddJsonObject(sb, "loadInBackground", importer.loadInBackground).Append(","); AssetsReporterUtils.AddJsonObject(sb, "preloadAudioData", importer.preloadAudioData).Append(","); // platform setting AudioImporterSampleSettings setting = importer.defaultSampleSettings; if (!string.IsNullOrEmpty(platform) && importer.ContainsSampleSettingsOverride(platform)) { setting = importer.GetOverrideSampleSettings(platform); } AssetsReporterUtils.AddJsonObject(sb, "loadType", setting.loadType.ToString()).Append(","); AssetsReporterUtils.AddJsonObject(sb, "compressionFormat", setting.compressionFormat.ToString()).Append(","); AssetsReporterUtils.AddJsonObject(sb, "sampleRateSetting", setting.sampleRateSetting.ToString()).Append(","); AssetsReporterUtils.AddJsonObject(sb, "sampleRateOverride", setting.sampleRateOverride.ToString()); sb.Append("}"); AssetsReporterUtils.AddCountDictionary(this.loadTypeSet, setting.loadType); AssetsReporterUtils.AddCountDictionary(this.ratingSet, setting.sampleRateOverride); AssetsReporterUtils.AddCountDictionary(this.compressSet, setting.compressionFormat); }
void OnPostprocessAudio(AudioClip clip) { AudioImporter importer = (AudioImporter)assetImporter; importer.forceToMono = true; AudioImporterSampleSettings defSetting = importer.defaultSampleSettings; if (importer.assetPath.Contains("Stroy") || importer.assetPath.Contains("Voice")) { importer.preloadAudioData = false; } if (clip.length > 10) { defSetting.loadType = AudioClipLoadType.CompressedInMemory; importer.defaultSampleSettings = defSetting; AudioImporterSampleSettings androidSetting = importer.GetOverrideSampleSettings("Android"); androidSetting.loadType = AudioClipLoadType.Streaming; importer.SetOverrideSampleSettings("Android", androidSetting); } else { defSetting.loadType = AudioClipLoadType.DecompressOnLoad; defSetting.compressionFormat = AudioCompressionFormat.ADPCM; importer.defaultSampleSettings = defSetting; } }
/// <summary> /// 复制音频导入器 /// </summary> public static void CopyAudioImporter(AudioImporter targetImporter, AudioImporter templateImporter) { // 通用属性 targetImporter.forceToMono = templateImporter.forceToMono; targetImporter.loadInBackground = templateImporter.loadInBackground; targetImporter.ambisonic = templateImporter.ambisonic; targetImporter.defaultSampleSettings = templateImporter.defaultSampleSettings; // 平台设置 AudioImporterSampleSettings sampleSettingsPC = templateImporter.GetOverrideSampleSettings("Standalone"); AudioImporterSampleSettings sampleSettingsIOS = templateImporter.GetOverrideSampleSettings("iOS"); AudioImporterSampleSettings sampleSettingsAndroid = templateImporter.GetOverrideSampleSettings("Android"); targetImporter.SetOverrideSampleSettings("Standalone", sampleSettingsPC); targetImporter.SetOverrideSampleSettings("iOS", sampleSettingsIOS); targetImporter.SetOverrideSampleSettings("Android", sampleSettingsAndroid); }
private bool IsEqual(AudioImporter target) { AudioImporter reference = referenceImporter as AudioImporter; UnityEngine.Assertions.Assert.IsNotNull(reference); if (!IsEqualAudioSampleSetting(target.defaultSampleSettings, reference.defaultSampleSettings)) { return(false); } foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups) { var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g, BuildTargetUtility.PlatformNameType.AudioImporter); if (target.ContainsSampleSettingsOverride(platformName) != reference.ContainsSampleSettingsOverride(platformName)) { return(false); } if (target.ContainsSampleSettingsOverride(platformName)) { var t = target.GetOverrideSampleSettings(platformName); var r = reference.GetOverrideSampleSettings(platformName); if (!IsEqualAudioSampleSetting(t, r)) { return(false); } } } if (target.forceToMono != reference.forceToMono) { return(false); } // using "!UNITY_5_6_OR_NEWER" instead of "Unity_5_6" because loadInBackground became obsolete after Unity 5.6b3. #if !UNITY_5_6_OR_NEWER if (target.loadInBackground != reference.loadInBackground) { return(false); } #endif #if UNITY_2017_1_OR_NEWER if (target.ambisonic != reference.ambisonic) { return(false); } #endif if (target.preloadAudioData != reference.preloadAudioData) { return(false); } return(true); }
/// <summary> /// 更改音效设置 /// </summary> /// <param name="importer"></param> /// <param name="platform"></param> /// <param name="loadType"></param> public static void SetAudioSettingExt(this AudioImporter importer, string platform, AudioClipLoadType loadType, AudioCompressionFormat format, float quality = 1) { AudioImporterSampleSettings settings = importer.GetOverrideSampleSettings(platform); settings.loadType = loadType; settings.compressionFormat = format; settings.quality = quality; importer.SetOverrideSampleSettings(platform, settings); }
protected override bool IsEqual(AssetImporter importer, AssetImporter templeteImproter) { AudioImporter reference = templeteImproter as AudioImporter; AudioImporter target = importer as AudioImporter; UnityEngine.Assertions.Assert.IsNotNull(reference); if (!IsEqualAudioSampleSetting(target.defaultSampleSettings, reference.defaultSampleSettings)) { return(false); } foreach (var platformName in new string[] { "Android", "iOS" }) { if (target.ContainsSampleSettingsOverride(platformName) != reference.ContainsSampleSettingsOverride(platformName)) { return(false); } if (target.ContainsSampleSettingsOverride(platformName)) { var t = target.GetOverrideSampleSettings(platformName); var r = reference.GetOverrideSampleSettings(platformName); if (!IsEqualAudioSampleSetting(t, r)) { return(false); } } } if (target.forceToMono != reference.forceToMono) { return(false); } // using "!UNITY_5_6_OR_NEWER" instead of "Unity_5_6" because loadInBackground became obsolete after Unity 5.6b3. #if !UNITY_5_6_OR_NEWER if (target.loadInBackground != reference.loadInBackground) { return(false); } #endif #if UNITY_2017_1_OR_NEWER if (target.ambisonic != reference.ambisonic) { return(false); } #endif if (target.preloadAudioData != reference.preloadAudioData) { return(false); } return(true); }
private void Initialize() { audioClipImporter = Importer as AudioImporter; audioClip = EditorResources.Load <AudioClip>(Importer.assetPath); foreach (var platform in Platforms) { platformMap[platform] = audioClipImporter.GetOverrideSampleSettings(platform); } }
public static APAudio GetAPAudioFromAssetGuid(string guid) { AudioImporter audioImporter = GetAssetImporterFromAssetGuid <AudioImporter>(guid); if (audioImporter == null) { return(null); } APAudio audio = new APAudio(); string path = AssetDatabase.GUIDToAssetPath(guid); audio.Icon = GetIconID(path); AudioClip audioClip = AssetDatabase.LoadAssetAtPath(path, typeof(AudioClip)) as AudioClip; if (audioClip == null) { return(null); } audio.Name = Utility.GetFileName(path); audio.FileSize = Utility.GetFileSize(path); audio.Background = audioImporter.loadInBackground; string platform = EditorUserBuildSettings.activeBuildTarget.ToString(); AudioImporterSampleSettings settings = audioImporter.defaultSampleSettings; if (audioImporter.ContainsSampleSettingsOverride(platform)) { settings = audioImporter.GetOverrideSampleSettings(EditorUserBuildSettings.activeBuildTarget.ToString()); } Type t = typeof(AudioImporter); var comSizeProperty = t.GetProperty("compSize", BindingFlags.NonPublic | BindingFlags.Instance); if (comSizeProperty != null) { audio.ImportedSize = long.Parse(comSizeProperty.GetValue(audioImporter, null).ToString()); } audio.Path = path; audio.Hash = Utility.GetFileMd5(path); audio.Ratio = audio.ImportedSize * 100f / audio.FileSize; audio.Quality = settings.quality; audio.Compress = settings.compressionFormat; audio.Duration = Utility.GetTimeDurationString(TimeSpan.FromSeconds(audioClip.length)); audio.Frequency = AudioUtil.GetFrequency(audioClip); audio.Id = guid; UnloadAsset(audioClip); return(audio); }
public override void SetResObj(Object obj) { resObj = obj; clip = obj as AudioClip; audioImporter = AssetImporter.GetAtPath(path) as AudioImporter; setting = ResourceAuditingSetting.GetIntance(); if (clip.length > setting.autioLengthThreshold) { autioType = "Long"; } else { autioType = "Short"; } //standalone_setting = GetPlatformSetting(audioImporter.GetOverrideSampleSettings(EditPlatform.Standalone), new TextuteFormatKey[] { }, new TextuteFormatKey[] { }); ios_setting = GetPlatformSetting(audioImporter.GetOverrideSampleSettings(EditPlatform.iPhone), EditPlatform.iPhone, setting.audioClipLoadType_Short_Ios, setting.compressionFormat_Short_Ios, setting.audioClipLoadType_Long_Ios, setting.compressionFormat_Long_Ios); android_setting = GetPlatformSetting(audioImporter.GetOverrideSampleSettings(EditPlatform.Android), EditPlatform.Android, setting.audioClipLoadType_Short_Android, setting.compressionFormat_Short_Android, setting.audioClipLoadType_Long_Android, setting.compressionFormat_Long_Android); }
private bool IsEqual(AudioImporter target, AudioImporter reference) { UnityEngine.Assertions.Assert.IsNotNull(reference); if (!IsEqualAudioSampleSetting(target.defaultSampleSettings, reference.defaultSampleSettings)) { return(false); } foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups) { var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g, BuildTargetUtility.PlatformNameType.AudioImporter); if (target.ContainsSampleSettingsOverride(platformName) != reference.ContainsSampleSettingsOverride(platformName)) { return(false); } if (target.ContainsSampleSettingsOverride(platformName)) { var t = target.GetOverrideSampleSettings(platformName); var r = reference.GetOverrideSampleSettings(platformName); if (!IsEqualAudioSampleSetting(t, r)) { return(false); } } } if (target.forceToMono != reference.forceToMono) { return(false); } if (target.loadInBackground != reference.loadInBackground) { return(false); } if (target.ambisonic != reference.ambisonic) { return(false); } if (target.preloadAudioData != reference.preloadAudioData) { return(false); } return(true); }
public ItemAudioClip(string path, UnityEngine.Object obj) : base(path, obj) { AudioClip audioClip = (AudioClip)obj; Frequency = audioClip.frequency; Channels = audioClip.channels; Length = audioClip.length; Samples = audioClip.samples; AudioImporter importer = (AudioImporter)AssetImporter.GetAtPath(path); string platform = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget).ToString(); AudioImporterSampleSettings settings = importer.GetOverrideSampleSettings(platform); CompressionFormat = settings.compressionFormat; CompressionQuality = settings.quality; }
public static AudioInfo CreateAudioInfo(string assetPath) { if (!EditorPath.IsAudio(assetPath)) { return(null); } AudioInfo audioInfo = null; if (!_dictAudioInfo.TryGetValue(assetPath, out audioInfo)) { audioInfo = new AudioInfo(); _dictAudioInfo.Add(assetPath, audioInfo); } AudioImporter audioImporter = AssetImporter.GetAtPath(assetPath) as AudioImporter; AudioClip audioClip = AssetDatabase.LoadAssetAtPath <AudioClip>(assetPath); if (audioImporter == null || audioClip == null) { Debug.LogError("audioImporter is empty"); return(null); } audioInfo.Path = assetPath; audioInfo.ForceToMono = audioImporter.forceToMono; audioInfo.LoadInBackground = audioImporter.loadInBackground; audioInfo.Ambisonic = audioImporter.ambisonic; audioInfo.MemSize = EditorTool.GetRuntimeMemorySize(audioClip); audioInfo.ImportedSize = EditorTool.GetRuntimeMemorySize(audioClip); audioInfo.StandAloneAudioClipLoadType = audioImporter.GetOverrideSampleSettings("Standalone").loadType; audioInfo.AndroidAudioClipLoadType = audioImporter.GetOverrideSampleSettings("Android").loadType; audioInfo.iOSAudioClipLoadType = audioImporter.GetOverrideSampleSettings("iOS").loadType; audioInfo.StandAloneAudioCompressionFormat = audioImporter.GetOverrideSampleSettings("Standalone").compressionFormat; audioInfo.AndroidAudioCompressionFormat = audioImporter.GetOverrideSampleSettings("Android").compressionFormat; audioInfo.iOSAudioCompressionFormat = audioImporter.GetOverrideSampleSettings("iOS").compressionFormat; audioInfo.OriginSize = ViewerConst.GetInternalValue <int>(audioImporter, "get_origSize", null); audioInfo.CompressedSize = ViewerConst.GetInternalValue <int>(audioImporter, "get_compSize", null); if (++_loadCount % 256 == 0) { Resources.UnloadUnusedAssets(); } return(audioInfo); }
private void OnGUI() { style.normal.textColor = Color.red; GUILayout.Label("建议 小于200k : " + AudioClipLoadType.DecompressOnLoad + " 大于200k小于1M : " + AudioClipLoadType.CompressedInMemory + " 大于1M : " + AudioClipLoadType.Streaming, style); style.normal.textColor = Color.black; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Path:"); currenAudioClipImportData.AssetPath = EditorGUILayout.TextField(currenAudioClipImportData.AssetPath); EditorGUILayout.LabelField("NameFilter:", GUILayout.MinWidth(200)); currenAudioClipImportData.FileFilter = EditorGUILayout.TextField(currenAudioClipImportData.FileFilter); if (GUILayout.Button("Save", GUILayout.MinWidth(100))) { SetSelectIndexDataInfo(); } if (GUILayout.Button("Delete", GUILayout.MinWidth(100))) { AudioClipImportManager.ImportRule.Delete(currentSelectIndex); } if (GUILayout.Button("New Data", GUILayout.MinWidth(100))) { if (string.IsNullOrEmpty(currenAudioClipImportData.AssetPath) || string.IsNullOrEmpty(currenAudioClipImportData.FileFilter)) { return; } AudioClipImportManager.AudioClipImportRule.AudioClipImportData data = GetNextAudioClipImportData(); data.AssetPath = currenAudioClipImportData.AssetPath; data.FileFilter = currenAudioClipImportData.FileFilter; AudioClipImportManager.ImportRule.Add(data); currenAudioClipImportData = data; currentSelectIndex = data.Index; GetSelectIndexDataInfo(data); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); { androidClipType = (AudioCompressionFormat)EditorGUILayout.EnumPopup("Android Compression类型", androidClipType); androidLoadType = (AudioClipLoadType)EditorGUILayout.EnumPopup("Android Load类型", androidLoadType); SetAndroidFormatInfo(); iPhoneClipType = (AudioCompressionFormat)EditorGUILayout.EnumPopup("iPhone Compression类型", iPhoneClipType); iPhoneLoadType = (AudioClipLoadType)EditorGUILayout.EnumPopup("iPhone Load类型", iPhoneLoadType); SetiPhoneFormatInfo(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); { currenAudioClipImportData.IsForceToMono = EditorGUILayout.ToggleLeft("是否开启ForceToMono", currenAudioClipImportData.IsForceToMono); currenAudioClipImportData.IsLoadInBackground = EditorGUILayout.ToggleLeft("是否开启LoadInBackground", currenAudioClipImportData.IsLoadInBackground); currenAudioClipImportData.IsAmbisonic = EditorGUILayout.ToggleLeft("是否开启Ambisonic", currenAudioClipImportData.IsAmbisonic); currenAudioClipImportData.IsPreloadAudioClip = EditorGUILayout.ToggleLeft("是否开启PreloadAudioClip", currenAudioClipImportData.IsPreloadAudioClip); currenAudioClipImportData.Index = EditorGUILayout.IntField("Rule Index", currenAudioClipImportData.Index); currenAudioClipImportData.Quality = EditorGUILayout.IntField("Quality", currenAudioClipImportData.Quality); } EditorGUILayout.EndHorizontal(); GUILayout.Space(25); int height = (AudioClipImportManager.ImportRule.AudioClipImportDatas.Count + 1) * 20; AudioClipImportManager.AudioClipImportRule.AudioClipImportData rule = AudioClipImportManager.ImportRule.GetRule(currentSelectIndex); string[] guids = null; if (null != rule) { guids = AssetDatabase.FindAssets("t:AudioClip", new string[] { rule.AssetPath }); height += (guids.Length + 1) * 20; } scrollPosition = GUI.BeginScrollView(new Rect(0, 30, position.width, position.height - 30), scrollPosition, new Rect(0, 0, 1250, height)); EditorGUILayout.BeginHorizontal(); { GUILayout.Label("AssetPath", EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label("FileFilter", EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label("Index", EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label("ForceToMono", EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label("LoadInBackground", EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label("Ambisonic", EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label("PreloadAudioClip", EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label("Quality", EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label("AndroidFormat", EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label("AndroidLoadType", EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label("iPhoneFormat", EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label("iPhoneLoadType", EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label("Apply", EditorStyles.label, GUILayout.MinWidth(100)); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); style = GUI.skin.textField; for (int i = 0; i < AudioClipImportManager.ImportRule.AudioClipImportDatas.Count; i++) { EditorGUILayout.BeginHorizontal(); AudioClipImportManager.AudioClipImportRule.AudioClipImportData data = AudioClipImportManager.ImportRule.AudioClipImportDatas[i]; GUI.color = data.Index == currentSelectIndex ? Color.green : new Color(0.8f, 0.8f, 0.8f, 1); if (GUILayout.Button(data.AssetPath, style, GUILayout.MinWidth(100))) { currentSelectIndex = data.Index; GetSelectIndexDataInfo(data); } if (GUILayout.Button(data.FileFilter, style, GUILayout.MinWidth(100))) { currentSelectIndex = data.Index; GetSelectIndexDataInfo(data); } if (GUILayout.Button(data.Index.ToString(), style, GUILayout.MinWidth(100))) { currentSelectIndex = data.Index; GetSelectIndexDataInfo(data); } if (GUILayout.Button(data.IsForceToMono.ToString(), style, GUILayout.MinWidth(100))) { currentSelectIndex = data.Index; GetSelectIndexDataInfo(data); } if (GUILayout.Button(data.IsLoadInBackground.ToString(), style, GUILayout.MinWidth(100))) { currentSelectIndex = data.Index; GetSelectIndexDataInfo(data); } if (GUILayout.Button(data.IsAmbisonic.ToString(), style, GUILayout.MinWidth(100))) { currentSelectIndex = data.Index; GetSelectIndexDataInfo(data); } if (GUILayout.Button(data.IsPreloadAudioClip.ToString(), style, GUILayout.MinWidth(100))) { currentSelectIndex = data.Index; GetSelectIndexDataInfo(data); } if (GUILayout.Button(data.Quality.ToString(), style, GUILayout.MinWidth(100))) { currentSelectIndex = data.Index; GetSelectIndexDataInfo(data); } if (GUILayout.Button(data.AndroidCompressionFormat.ToString(), style, GUILayout.MinWidth(100))) { currentSelectIndex = data.Index; GetSelectIndexDataInfo(data); } if (GUILayout.Button(data.AndroidAudioClipLoadType.ToString(), style, GUILayout.MinWidth(100))) { currentSelectIndex = data.Index; GetSelectIndexDataInfo(data); } if (GUILayout.Button(data.iPhoneCompressionFormat.ToString(), style, GUILayout.MinWidth(100))) { currentSelectIndex = data.Index; GetSelectIndexDataInfo(data); } if (GUILayout.Button(data.iPhoneClipLoadType.ToString(), style, GUILayout.MinWidth(100))) { currentSelectIndex = data.Index; GetSelectIndexDataInfo(data); } if (GUILayout.Button("Apply", GUILayout.MinWidth(100))) { AudioClipImportManager.ReImportAudioClips(data); } EditorGUILayout.EndHorizontal(); } if (null != guids) { int count = 0; for (int i = 0; i < guids.Length; i++) { string path = AssetDatabase.GUIDToAssetPath(guids[i]); if (string.IsNullOrEmpty(path)) { continue; } string dir = path.Remove(path.LastIndexOf('/')); if (!dir.Equals(currenAudioClipImportData.AssetPath)) { continue; } string fileName = path.Substring(path.LastIndexOf('/') + 1); if (!currenAudioClipImportData.IsMatch(fileName)) { continue; } AudioImporter ai = AssetImporter.GetAtPath(path) as AudioImporter; if (null != ai) { EditorGUILayout.BeginHorizontal(); { GUILayout.Label(fileName, EditorStyles.label, GUILayout.MinWidth(120)); GUILayout.Label("", EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label((++count).ToString(), EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label(ai.forceToMono.ToString(), EditorStyles.label, GUILayout.MinWidth(120)); GUILayout.Label(ai.loadInBackground.ToString(), EditorStyles.label, GUILayout.MinWidth(120)); GUILayout.Label(ai.ambisonic.ToString(), EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label(ai.preloadAudioData.ToString(), EditorStyles.label, GUILayout.MinWidth(100)); AudioImporterSampleSettings settingAndroid = ai.GetOverrideSampleSettings("Android"); AudioImporterSampleSettings settingiPhone = ai.GetOverrideSampleSettings("iOS"); GUILayout.Label(settingAndroid.quality.ToString(), EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label(settingAndroid.compressionFormat.ToString(), EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label(settingAndroid.loadType.ToString(), EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label(settingiPhone.compressionFormat.ToString(), EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label(settingiPhone.loadType.ToString(), EditorStyles.label, GUILayout.MinWidth(100)); GUILayout.Label("", EditorStyles.label, GUILayout.MinWidth(100)); } EditorGUILayout.EndHorizontal(); } } } GUI.EndScrollView(); if (EditorUtility.IsDirty(AudioClipImportManager.ImportRule)) { EditorUtility.SetDirty(AudioClipImportManager.ImportRule); AssetDatabase.Refresh(); } }
/// <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(); }; }
public static void DealAudioImporter(AudioClip clip, AudioImporter importer, bool forceMono, bool bSensitive = false, bool compressSampleRate = true) { bool bChange = false; if (clip == null) { return; } AudioImporterSampleSettings androidSetting = importer.GetOverrideSampleSettings("Android"); AudioImporterSampleSettings iosSetting = importer.GetOverrideSampleSettings("iPhone"); if (clip.length >= 10) { if (androidSetting.loadType != AudioClipLoadType.Streaming) { androidSetting.loadType = AudioClipLoadType.Streaming; iosSetting.loadType = AudioClipLoadType.Streaming; bChange = true; } AudioCompressionFormat newFmt = AudioCompressionFormat.Vorbis; if (newFmt != androidSetting.compressionFormat) { androidSetting.compressionFormat = newFmt; iosSetting.compressionFormat = newFmt; androidSetting.quality = 0.01f; iosSetting.quality = 0.01f; bChange = true; } } else if (clip.length < 10 && clip.length >= 1) { AudioClipLoadType newLoadType = AudioClipLoadType.CompressedInMemory; if (newLoadType != androidSetting.loadType) { androidSetting.loadType = newLoadType; iosSetting.loadType = newLoadType; bChange = true; } AudioCompressionFormat newFmt = bSensitive ? AudioCompressionFormat.ADPCM : AudioCompressionFormat.Vorbis; if (newFmt != androidSetting.compressionFormat) { androidSetting.compressionFormat = newFmt; iosSetting.compressionFormat = newFmt; bChange = true; if (newFmt == AudioCompressionFormat.Vorbis) { androidSetting.quality = 0.01f; iosSetting.quality = 0.01f; } } } else if (clip.length < 1) { AudioClipLoadType newLoadType = bSensitive ? AudioClipLoadType.DecompressOnLoad : AudioClipLoadType.CompressedInMemory; if (androidSetting.loadType != newLoadType) { androidSetting.loadType = newLoadType; iosSetting.loadType = newLoadType; bChange = true; } AudioCompressionFormat newFmt = AudioCompressionFormat.ADPCM; if (newFmt != androidSetting.compressionFormat) { androidSetting.compressionFormat = newFmt; iosSetting.compressionFormat = newFmt; bChange = true; } } var sampleRate = (uint)(compressSampleRate ? 22050 : 44100); if (androidSetting.sampleRateSetting != AudioSampleRateSetting.OverrideSampleRate || androidSetting.sampleRateOverride != sampleRate) { androidSetting.sampleRateSetting = AudioSampleRateSetting.OverrideSampleRate; iosSetting.sampleRateSetting = AudioSampleRateSetting.OverrideSampleRate; androidSetting.sampleRateOverride = sampleRate; iosSetting.sampleRateOverride = sampleRate; bChange = true; } if (importer.forceToMono != forceMono) { importer.forceToMono = forceMono; bChange = true; } if (importer.loadInBackground && androidSetting.loadType != AudioClipLoadType.Streaming) { importer.loadInBackground = false; bChange = true; } if (importer.preloadAudioData) { importer.preloadAudioData = false; bChange = true; } if (bChange) { importer.SetOverrideSampleSettings("Android", androidSetting); importer.SetOverrideSampleSettings("iPhone", iosSetting); importer.SaveAndReimport(); } }
/// <summary> Panel to show "Clip" options of Sequence </summary> /// <param name="inlineHelp">Should help be displayed?</param> public void ClipsPanel(bool inlineHelp) { ++EditorGUI.indentLevel; EditorGUI.BeginChangeCheck(); Rect clipsRect; if (m_clipsExpanded) { clipsRect = EditorGUILayout.GetControlRect(true, m_clipsReorderable.GetHeight()); m_clipsReorderable.DoList(clipsRect); } else { int oldIndent = EditorGUI.indentLevel; EditorGUI.indentLevel = 1; m_clipsExpanded = EditorGUILayout.Foldout(m_clipsExpanded, PropertyCount("mClips", m_clipData), true); clipsRect = GUILayoutUtility.GetLastRect(); EditorGUI.indentLevel = oldIndent; } if (Event.current.type == EventType.DragUpdated && clipsRect.Contains(Event.current.mousePosition)) { bool isValid = false; for (int i = 0; i < DragAndDrop.objectReferences.Length; ++i) { if (DragAndDrop.objectReferences[i] is AudioClip) { isValid = true; break; } } if (isValid) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; } else { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; } } else if (Event.current.type == EventType.DragPerform && clipsRect.Contains(Event.current.mousePosition)) { for (int i = 0; i < DragAndDrop.objectReferences.Length; ++i) { if (!(DragAndDrop.objectReferences[i] is AudioClip)) { continue; } int idx = m_clipData.arraySize; m_clipData.InsertArrayElementAtIndex(idx); SerializedProperty clipData = m_clipData.GetArrayElementAtIndex(idx); clipData.FindPropertyRelative("m_volume").floatValue = 1f; clipData.FindPropertyRelative("m_clip").objectReferenceValue = DragAndDrop.objectReferences[i]; } Event.current.Use(); } m_editorUtils.InlineHelp("mClips", inlineHelp); //PropertyCountField("mClips", true, m_clips, ((Sequence)target).m_clips.Length, inlineHelp); int badClipCount = 0; for (int x = 0; x < m_clipData.arraySize; ++x) { AudioClip clip = m_clipData.GetArrayElementAtIndex(x).FindPropertyRelative("m_clip").objectReferenceValue as AudioClip; if (clip != null) { if (clip.loadType != AudioClipLoadType.DecompressOnLoad) { ++badClipCount; } } } if (badClipCount > 0) { EditorGUILayout.HelpBox(m_editorUtils.GetContent("InvalidClipMessage").text, MessageType.Warning, true); if (m_editorUtils.ButtonRight("InvalidClipButton")) { GUIContent progressBarContent = m_editorUtils.GetContent("InvalidClipPopup"); for (int x = 0; x < m_clipData.arraySize; ++x) { AudioClip clip = m_clipData.GetArrayElementAtIndex(x).FindPropertyRelative("m_clip").objectReferenceValue as AudioClip; EditorUtility.DisplayProgressBar(progressBarContent.text, progressBarContent.tooltip + clip.name, x / (float)badClipCount); if (clip != null) { if (clip.loadType != AudioClipLoadType.DecompressOnLoad) { AudioImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(clip)) as AudioImporter; AudioImporterSampleSettings sampleSettings = importer.defaultSampleSettings; sampleSettings.loadType = AudioClipLoadType.DecompressOnLoad; importer.defaultSampleSettings = sampleSettings; if (importer.ContainsSampleSettingsOverride("Standalone")) { sampleSettings = importer.GetOverrideSampleSettings("Standalone"); sampleSettings.loadType = AudioClipLoadType.DecompressOnLoad; importer.SetOverrideSampleSettings("Standalone", sampleSettings); } importer.SaveAndReimport(); } } } EditorUtility.ClearProgressBar(); } } if (EditorGUI.EndChangeCheck() && Application.isPlaying) { (target as Sequence).UpdateModifiers(); } m_editorUtils.PropertyField("mTrackFadeTime", m_trackFadeTime, inlineHelp); if (m_trackFadeTime.floatValue < 0f) { m_trackFadeTime.floatValue = 0f; } m_editorUtils.PropertyField("mVolume", m_volume, inlineHelp); m_editorUtils.PropertyField("mVolumeFadeTime", m_volumeFadeTime, inlineHelp); if (m_volumeFadeTime.floatValue < 0f) { m_volumeFadeTime.floatValue = 0f; } EditorGUI.BeginDisabledGroup(syncGroup.target && ((SyncType)System.Enum.GetValues(typeof(SyncType)).GetValue(m_syncType.enumValueIndex) & SyncType.FIT) > 0); { m_editorUtils.PropertyField("mPlaybackSpeed", m_playbackSpeed, inlineHelp); if (m_playbackSpeed.floatValue < 0f) { m_playbackSpeed.floatValue = 0f; } } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(syncGroup.target); { m_editorUtils.PropertyField("mPlaybackSpeedFadeTime", m_playbackSpeedFadeTime, inlineHelp); if (m_playbackSpeedFadeTime.floatValue < 0f) { m_playbackSpeedFadeTime.floatValue = 0f; } m_editorUtils.PropertyField("mCrossFade", m_crossFade, inlineHelp); if (m_crossFade.floatValue < 0f) { m_crossFade.floatValue = 0f; } } EditorGUI.EndDisabledGroup(); --EditorGUI.indentLevel; }
/// <summary> Panel to display modifications to apply when active </summary> /// <param name="inlineHelp">Should help be displayed?</param> void ModificationsPanel(bool inlineHelp) { ++EditorGUI.indentLevel; ToggleField(EditorGUILayout.GetControlRect(), m_modClips, m_modClipsType, m_editorUtils.GetContent("mModClipsType")); m_editorUtils.InlineHelp("mModClipsType", inlineHelp); clipsVisible.target = m_modClips.boolValue; if (EditorGUILayout.BeginFadeGroup(clipsVisible.faded)) { if (m_clipsExpanded) { m_clipsReorderable.DoLayoutList(); } else { int oldIndent = EditorGUI.indentLevel; EditorGUI.indentLevel = 1; m_clipsExpanded = EditorGUILayout.Foldout(m_clipsExpanded, PropertyCount("mClips", m_clipData), true); EditorGUI.indentLevel = oldIndent; } m_editorUtils.InlineHelp("mClips", inlineHelp); int badClipCount = 0; for (int x = 0; x < m_clipData.arraySize; ++x) { AudioClip clip = m_clipData.GetArrayElementAtIndex(x).FindPropertyRelative("m_clip").objectReferenceValue as AudioClip; if (clip != null) { if (clip.loadType != AudioClipLoadType.DecompressOnLoad) { ++badClipCount; } } } if (badClipCount > 0) { EditorGUILayout.HelpBox(m_editorUtils.GetContent("InvalidClipMessage").text, MessageType.Warning, true); if (m_editorUtils.ButtonRight("InvalidClipButton")) { GUIContent progressBarContent = m_editorUtils.GetContent("InvalidClipPopup"); for (int x = 0; x < m_clipData.arraySize; ++x) { AudioClip clip = m_clipData.GetArrayElementAtIndex(x).FindPropertyRelative("m_clip").objectReferenceValue as AudioClip; EditorUtility.DisplayProgressBar(progressBarContent.text, progressBarContent.tooltip + clip.name, x / (float)badClipCount); if (clip != null) { if (clip.loadType != AudioClipLoadType.DecompressOnLoad) { AudioImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(clip)) as AudioImporter; AudioImporterSampleSettings sampleSettings = importer.defaultSampleSettings; sampleSettings.loadType = AudioClipLoadType.DecompressOnLoad; importer.defaultSampleSettings = sampleSettings; if (importer.ContainsSampleSettingsOverride("Standalone")) { sampleSettings = importer.GetOverrideSampleSettings("Standalone"); sampleSettings.loadType = AudioClipLoadType.DecompressOnLoad; importer.SetOverrideSampleSettings("Standalone", sampleSettings); } importer.SaveAndReimport(); } } } EditorUtility.ClearProgressBar(); } } } EditorGUILayout.EndFadeGroup(); ToggleField(EditorGUILayout.GetControlRect(), m_modVolume, m_volume, m_editorUtils.GetContent("mVolume")); m_editorUtils.InlineHelp("mVolume", inlineHelp); ToggleField(EditorGUILayout.GetControlRect(), m_modPlaybackSpeed, m_playbackSpeed, m_editorUtils.GetContent("mPlaybackSpeed")); m_editorUtils.InlineHelp("mPlaybackSpeed", inlineHelp); ToggleField(EditorGUILayout.GetControlRect(), m_modRandomizePlaybackSpeed, m_randomizePlaybackSpeed, m_editorUtils.GetContent("mRandomizePlaybackSpeed")); m_editorUtils.InlineHelp("mRandomizePlaybackSpeed", inlineHelp); ToggleSliderRangeField(EditorGUILayout.GetControlRect(), m_modMinMaxPlaybackSpeed, m_minMaxPlaybackSpeed, m_editorUtils.GetContent("mMinMaxPlaybackSpeed"), 0.01f, 3f); m_editorUtils.InlineHelp("mMinMaxPlaybackSpeed", inlineHelp); ToggleField(EditorGUILayout.GetControlRect(), m_modDelayChance, m_delayChance, m_editorUtils.GetContent("mDelayChance")); m_editorUtils.InlineHelp("mDelayChance", inlineHelp); ToggleVector2Field(EditorGUILayout.GetControlRect(), m_modDelay, m_minMaxDelay, m_editorUtils.GetContent("mMinMaxDelay"), m_editorUtils.GetContent("mMinPrefix"), m_editorUtils.GetContent("mMaxPrefix")); m_editorUtils.InlineHelp("mMinMaxDelay", inlineHelp); ToggleField(EditorGUILayout.GetControlRect(), m_modRandomizeVolume, m_randomizeVolume, m_editorUtils.GetContent("mRandomizeVolume")); m_editorUtils.InlineHelp("mRandomizeVolume", inlineHelp); ToggleSliderRangeField(EditorGUILayout.GetControlRect(), m_modMinMaxVolume, m_minMaxVolume, m_editorUtils.GetContent("mMinMaxVolume"), 0.01f, 2f); m_editorUtils.InlineHelp("mMinMaxVolume", inlineHelp); --EditorGUI.indentLevel; }
static void ApplyAudioImporter(ApplyData ad) { string assetPath = ad.assetPath; List <string> ignoreList = ad.ignoreList; TextureFormat tf = ad.tf; FormatPathPair fpp = ad.fpp; bool advanced = ad.advanced; string platformName = ad.platformName; bool needToCheck = ad.needToCheck; AudioImporter ai = AssetImporter.GetAtPath(assetPath) as AudioImporter; if (ai != null) { if (needToCheck) { for (int k = 0; k < ignoreList.Count; k++) { if (ignoreList[k] == assetPath) { return; } } } AudioImporterSampleSettings aiss; if (string.IsNullOrEmpty(platformName)) { for (int j = 0; j < 3; j++) { tf = fpp.GetFormatByPlatform(j); platformName = audioPlatforms[j]; if (ai.ContainsSampleSettingsOverride(platformName)) { aiss = ai.GetOverrideSampleSettings(platformName); if (aiss.loadType != tf.loadType || !ai.forceToMono) { aiss.loadType = tf.loadType; ai.forceToMono = true; if (!reimportList.Contains(assetPath)) { reimportList.Add(assetPath); } } } else if (ai.defaultSampleSettings.loadType != tf.loadType || !ai.forceToMono) { ai.forceToMono = true; aiss = ai.defaultSampleSettings; aiss.loadType = tf.loadType; ai.SetOverrideSampleSettings(platformName, aiss); if (!reimportList.Contains(assetPath)) { reimportList.Add(assetPath); } } } } else { if (platformName == platforms[2]) { platformName = "iOS"; } if (ai.ContainsSampleSettingsOverride(platformName)) { aiss = ai.GetOverrideSampleSettings(platformName); if (aiss.loadType != tf.loadType || !ai.forceToMono) { ai.forceToMono = true; aiss.loadType = tf.loadType; ai.SetOverrideSampleSettings(platformName, aiss); if (!reimportList.Contains(assetPath)) { reimportList.Add(assetPath); } } } else if (ai.defaultSampleSettings.loadType != tf.loadType || !ai.forceToMono) { ai.forceToMono = true; aiss = ai.defaultSampleSettings; aiss.loadType = tf.loadType; ai.SetOverrideSampleSettings(platformName, aiss); if (!reimportList.Contains(assetPath)) { reimportList.Add(assetPath); } } } } }
public override void InitDetailCheckObject(Object obj) { AudioClip clip = obj as AudioClip; AudioChecker checker = currentChecker as AudioChecker; string compression = buildInType; int quality = 0; string sampleRateSetting = buildInType; int overrideSampleRate = 0; string androidOverride = buildInType; string androidLoadType = buildInType; string androidCompression = buildInType; int androidQuality = 0; string androidSampleRateSetting = buildInType; int androidSampleRate = 0; string iosOverride = buildInType; string iosLoadType = buildInType; string iosCompression = buildInType; int iosQuality = 0; string iosSampleRateSetting = buildInType; int iosSampleRate = 0; AudioImporter importer = AudioImporter.GetAtPath(assetPath) as AudioImporter; if (importer != null) { compression = importer.defaultSampleSettings.compressionFormat.ToString(); quality = Mathf.Clamp((int)(importer.defaultSampleSettings.quality * 100), 1, 100); sampleRateSetting = importer.defaultSampleSettings.sampleRateSetting.ToString(); overrideSampleRate = (int)importer.defaultSampleSettings.sampleRateOverride; AudioImporterSampleSettings androidSettings = importer.GetOverrideSampleSettings(platformAndroid); androidOverride = importer.ContainsSampleSettingsOverride(platformAndroid).ToString(); androidLoadType = androidSettings.loadType.ToString(); androidCompression = androidSettings.compressionFormat.ToString(); androidQuality = Mathf.Clamp((int)(androidSettings.quality * 100), 1, 100); androidSampleRateSetting = androidSettings.sampleRateSetting.ToString(); androidSampleRate = (int)androidSettings.sampleRateOverride; AudioImporterSampleSettings iosSettings = importer.GetOverrideSampleSettings(platformIOS); iosOverride = importer.ContainsSampleSettingsOverride(platformIOS).ToString(); iosLoadType = iosSettings.loadType.ToString(); iosCompression = iosSettings.compressionFormat.ToString(); iosQuality = Mathf.Clamp((int)(iosSettings.quality * 100), 1, 100); iosSampleRateSetting = iosSettings.sampleRateSetting.ToString(); iosSampleRate = (int)iosSettings.sampleRateOverride; } checkMap.Add(checker.audioLength, clip.length); checkMap.Add(checker.audioType, clip.loadType.ToString()); checkMap.Add(checker.audioChannel, clip.channels); checkMap.Add(checker.audioCompression, compression); checkMap.Add(checker.audioQuality, quality); checkMap.Add(checker.audioSampleRateSetting, sampleRateSetting); checkMap.Add(checker.audioSampleRate, overrideSampleRate); checkMap.Add(checker.audioPostfix, ResourceCheckerHelper.GetAssetPostfix(assetPath)); checkMap.Add(checker.audioAndroidOverride, androidOverride); checkMap.Add(checker.audioAndroidLoadType, androidLoadType); checkMap.Add(checker.audioAndroidCompressionFormat, androidCompression); checkMap.Add(checker.audioAndroidQuality, androidQuality); checkMap.Add(checker.audioAndroidSampleRateSetting, androidSampleRateSetting); checkMap.Add(checker.audioAndroidSampleRate, androidSampleRate); checkMap.Add(checker.audioIOSOverride, iosOverride); checkMap.Add(checker.audioIOSLoadType, iosLoadType); checkMap.Add(checker.audioIOSCompressionFormat, iosCompression); checkMap.Add(checker.audioIOSQuality, iosQuality); checkMap.Add(checker.audioIOSSampleRateSetting, iosSampleRateSetting); checkMap.Add(checker.audioIOSSampleRate, iosSampleRate); }
public void SetAudioClipConfig(AudioClip clip) { string path = AssetDatabase.GetAssetPath(clip); AudioImporter audioImporter = AudioImporter.GetAtPath(path) as AudioImporter; if (audioImporter == null) { return; } AudioImporterSampleSettings settings = audioImporter.defaultSampleSettings; switch (target) { case ResourceTarget.Default: settings = audioImporter.defaultSampleSettings; break; case ResourceTarget.Android: settings = audioImporter.GetOverrideSampleSettings("Android"); break; case ResourceTarget.IOS: settings = audioImporter.GetOverrideSampleSettings("IOS"); break; } if (bForceToMono) { audioImporter.forceToMono = audioConfig.forceToMono; } if (bLoadInBackground) { audioImporter.loadInBackground = audioConfig.loadInBackground; } if (bAudioCompressionFormat) { settings.compressionFormat = audioConfig.defaultAudioSettings.compressionFormat; } if (bAudioLoadType) { settings.loadType = audioConfig.defaultAudioSettings.loadType; } if (bQuality) { settings.quality = audioConfig.defaultAudioSettings.quality; } if (bAudioSampleRateSetting) { settings.sampleRateSetting = audioConfig.defaultAudioSettings.sampleRateSetting; } switch (target) { case ResourceTarget.Default: audioImporter.defaultSampleSettings = settings; break; case ResourceTarget.Android: audioImporter.SetOverrideSampleSettings("Android", settings); break; case ResourceTarget.IOS: audioImporter.SetOverrideSampleSettings("IOS", settings); break; } audioImporter.SaveAndReimport(); }