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(); }
void OnPreprocessAudio() { AudioImporter audioImporter = (AudioImporter)assetImporter; AudioClip audioClip = AssetDatabase.LoadAssetAtPath <AudioClip>(audioImporter.assetPath); if (audioClip != null) { if (audioImporter.defaultSampleSettings.loadType != AudioClipLoadType.CompressedInMemory && audioClip.length > 1.5) { var defaultSampleSettings = audioImporter.defaultSampleSettings; defaultSampleSettings.loadType = AudioClipLoadType.CompressedInMemory; audioImporter.defaultSampleSettings = defaultSampleSettings; defaultSampleSettings.quality = 0.7f; audioImporter.SaveAndReimport(); } // else if (audioImporter.defaultSampleSettings.quality > 0.72) { // var defaultSampleSettings = audioImporter.defaultSampleSettings; // defaultSampleSettings.quality = 0.7f; // audioImporter.SaveAndReimport(); // } } // if (assetPath.Contains("mono")) { // // var audioImporter : AudioImporter = assetImporter; // audioImporter.forceToMono = true; // } }
static void ChangeAudioImportSettings(string path) { AudioImporter imp = AssetImporter.GetAtPath(path) as AudioImporter; imp.loadInBackground = true; imp.preloadAudioData = false; AudioImporterSampleSettings settings = imp.defaultSampleSettings; settings.compressionFormat = AudioCompressionFormat.Vorbis; imp.defaultSampleSettings = settings; imp.SaveAndReimport(); }
public bool Fix(string path) { AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter; if (audioImporter == null) { return(true); } audioImporter.forceToMono = true; audioImporter.SaveAndReimport(); return(true); }
private static void CompVorbis70() { AudioClip[] clip = Selection.GetFiltered <AudioClip>(SelectionMode.DeepAssets); AssetDatabase.StartAssetEditing(); { int guidCount = clip.Length; for (int i = 0; i < guidCount; ++i) { string assetPath = AssetDatabase.GetAssetPath(clip[i]); EditorUtility.DisplayProgressBar(string.Format("Setting Import Settings [{0} / {1}]", i, guidCount), assetPath, i / (float)guidCount); AudioImporter importer = (AudioImporter)AudioImporter.GetAtPath(assetPath); if (importer != null) { bool changed = false; AudioImporterSampleSettings settings = importer.defaultSampleSettings; if (changed |= (settings.loadType != AudioClipLoadType.CompressedInMemory)) { settings.loadType = AudioClipLoadType.CompressedInMemory; } if (changed |= (settings.compressionFormat != AudioCompressionFormat.Vorbis)) { settings.compressionFormat = AudioCompressionFormat.Vorbis; } if (changed |= (settings.quality != 0.7f)) { settings.quality = 0.7f; } if (changed |= (settings.sampleRateSetting != AudioSampleRateSetting.PreserveSampleRate)) { settings.sampleRateSetting = AudioSampleRateSetting.PreserveSampleRate; } if (changed == true) { importer.defaultSampleSettings = settings; importer.SaveAndReimport(); } } } EditorUtility.ClearProgressBar(); } AssetDatabase.StopAssetEditing(); AssetDatabase.SaveAssets(); }
static void Uncompressed() { string[] folder = { "Assets/assetbundle/sound", }; string [] acs = AssetDatabase.FindAssets("t:AudioClip", folder); int n = acs.Length; AssetDatabase.StartAssetEditing(); for (int i = 0; i < n; i++) { string path = AssetDatabase.GUIDToAssetPath(acs[i]); if (EditorUtility.DisplayCancelableProgressBar(string.Format("{0}", path), i + "/" + acs.Length, (float)i / (float)acs.Length)) { break; } // Debug.LogFormat("reimport {0}/{1}: {2}", i+1, n, path); AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter; if (audioImporter == null) { continue; } AudioClipLoadType t = AudioClipLoadType.DecompressOnLoad; AudioClip clip = AssetDatabase.LoadAssetAtPath <AudioClip>(path); if (clip.length >= 5) { t = AudioClipLoadType.Streaming; } AudioImporterSampleSettings audioImporterSampleSettings = audioImporter.defaultSampleSettings; if (audioImporterSampleSettings.loadType != t) { Debug.LogFormat("{0} {1} {2}", path, clip.length, t); audioImporterSampleSettings.loadType = AudioClipLoadType.Streaming; audioImporter.defaultSampleSettings = audioImporterSampleSettings; audioImporter.SaveAndReimport(); } } AssetDatabase.StopAssetEditing(); // AssetDatabase.SaveAssets(); // AssetDatabase.Refresh(); EditorUtility.ClearProgressBar(); }
/// <summary> /// 音频的压缩相关设置 /// </summary> void OnPreprocessAudio() { if (IsImported()) { return; } AudioImporter importer = assetImporter as AudioImporter; // 根据音频时长来设置压缩方式 AudioClip clip = AssetDatabase.LoadAssetAtPath <AudioClip>(importer.assetPath); if (clip == null) { importer.SaveAndReimport();// 加载音频数据失败(添加新文件)时,重新再来 return; } AudioImporterSampleSettings setting = new AudioImporterSampleSettings { sampleRateSetting = AudioSampleRateSetting.OptimizeSampleRate, quality = 0.8f }; float length = clip.length; if (length < 5) { // 短音效 setting.loadType = AudioClipLoadType.DecompressOnLoad; setting.compressionFormat = AudioCompressionFormat.PCM; } else if (length < 15) { // 中等长度音效 setting.loadType = AudioClipLoadType.CompressedInMemory; setting.compressionFormat = AudioCompressionFormat.ADPCM; } else { // BGM setting.loadType = AudioClipLoadType.CompressedInMemory; setting.compressionFormat = AudioCompressionFormat.Vorbis; } importer.forceToMono = true; importer.preloadAudioData = true; importer.defaultSampleSettings = setting; MarkImported(); }
//Method that automatically runs when a new audio file is added to the Unity Project. Will always run when a new Audio File is added to the process. void OnPreprocessAudio() { //First checks if the asset is going into any folder labeled "Audio", otherwise it will not run the rest of the code at all. if (assetPath.Contains("Audio")) { //Settings are obtained from the Audio Configuration Class to allow for easy access to the already selected choices. //Audio importer must save and Reimport for the changes to take effect, otherwise the changes will not apply to the file. AudioImporter audioImporter = (AudioImporter)assetImporter; AudioImporterSampleSettings settings = audioImporter.defaultSampleSettings; settings.compressionFormat = AudioConfigruationFile.clipCompressionFormatSetting; settings.sampleRateSetting = AudioSampleRateSetting.OverrideSampleRate; settings.sampleRateOverride = AudioConfigruationFile.clipSampleRateSetting; settings.loadType = AudioConfigruationFile.clipLoadTypeSetting; audioImporter.SetOverrideSampleSettings(AudioConfigruationFile.platformOverrideSetting, settings); audioImporter.SaveAndReimport(); } }
public void OnPreprocessAudio() { AudioImporter importer = (AudioImporter)assetImporter; if (!importer.forceToMono) { if (fixForceToMono) { importer.forceToMono = true; importer.SaveAndReimport(); Debug.Log("Audio auto check forceToMono:" + importer.assetPath); } else { Debug.LogWarning("Audio forceToMono is unchecked:" + importer.assetPath); } } }
private static void ClearHighSampleRate() { AudioClip[] clip = Selection.GetFiltered <AudioClip>(SelectionMode.DeepAssets); AssetDatabase.StartAssetEditing(); { int guidCount = clip.Length; for (int i = 0; i < guidCount; ++i) { string assetPath = AssetDatabase.GetAssetPath(clip[i]); EditorUtility.DisplayProgressBar(string.Format("Setting Import Settings [{0} / {1}]", i, guidCount), assetPath, i / (float)guidCount); AudioImporter importer = (AudioImporter)AudioImporter.GetAtPath(assetPath); if (importer != null) { bool changed = false; AudioImporterSampleSettings settings = importer.defaultSampleSettings; if (changed |= clip[i].frequency > 48000) { settings.sampleRateSetting = AudioSampleRateSetting.OverrideSampleRate; settings.sampleRateOverride = 48000; } if (changed == true) { importer.defaultSampleSettings = settings; importer.SaveAndReimport(); } } } EditorUtility.ClearProgressBar(); } AssetDatabase.StopAssetEditing(); AssetDatabase.SaveAssets(); }
public static bool DownloadMusicToFile(string url, string path) { if (!DownloadAssetToFile(url, path)) { return(false); } AudioImporter audioImporter = (AudioImporter)AssetImporter.GetAtPath(path); audioImporter.preloadAudioData = true; audioImporter.loadInBackground = false; AudioImporterSampleSettings sampleSettings = audioImporter.defaultSampleSettings; sampleSettings.compressionFormat = AudioCompressionFormat.Vorbis; sampleSettings.loadType = AudioClipLoadType.Streaming; sampleSettings.quality = 1.0f; audioImporter.defaultSampleSettings = sampleSettings; audioImporter.SaveAndReimport(); return(true); }
/// <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; }
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(); } }
private void LoadFile(string fsFilePath) { try { string sourceFileName = Path.GetFileName(fsFilePath); string destAssetPath = Path.Combine(TempRelativeFolderPath, sourceFileName); if (!sourceFileName.Contains(TempRelativeFolderPath)) { destAssetPath = GeneratePath(TempRelativeFolderPath, sourceFileName); if (string.IsNullOrEmpty(destAssetPath)) { throw new ApplicationException("Can't locate audio path. "); } string destFsFilePath = Path.Combine(rootProjectFolder, destAssetPath); soundManager.SetState(StateId.CopyToTempFolderInProgress, "Copy file from " + fsFilePath + " to " + destFsFilePath); try { if (File.Exists(destFsFilePath)) { File.Delete(destFsFilePath); } File.Copy(fsFilePath, destFsFilePath); } catch (UnityException exp) { Debug.LogError(exp.Message); } #if UNITY_EDITOR AssetDatabase.ImportAsset(destAssetPath, ImportAssetOptions.ForceUncompressedImport); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); #endif } audioImporter = AudioImporter.GetAtPath(destAssetPath) as AudioImporter; if (audioImporter == null) { soundManager.SetState(StateId.Abort, "Aborted as file " + destAssetPath + " has incompatible format"); return; } audioImporter.preloadAudioData = false; audioImporter.forceToMono = false; audioImporter.loadInBackground = false; audioImporter.defaultSampleSettings = audioImporterSettings; soundManager.SetState(StateId.LoadingAudioData, "Import " + destAssetPath); audioImporter.SaveAndReimport(); #if UNITY_EDITOR audioClip = AssetDatabase.LoadAssetAtPath(destAssetPath, typeof(AudioClip)) as AudioClip; #endif if (audioClip == null || !audioClip.LoadAudioData()) { soundManager.SetState(StateId.Abort, "Aborted: Can't load " + destAssetPath + " as audioclip"); return; } soundManager.audioClip = audioClip; soundManager.audioImporter = audioImporter; soundManager.SetState(StateId.DataLoaded, "Loaded " + destAssetPath); } catch (UnityException exp) { Debug.LogError(exp.Message); throw; } }
/// <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; }
public static void FixRule(AssetAuditTreeElement data, AssetRule assetRule) { string ruleAssetPath = AssetDatabase.GUIDToAssetPath(assetRule.AssetGuid); string affectedAssetPath = data.projectPath; switch (data.assetType) { case AssetType.Texture: TextureImporter ruleTexImporter = AssetImporter.GetAtPath(ruleAssetPath) as TextureImporter; TextureImporter affectedAssetTexImporter = AssetImporter.GetAtPath(affectedAssetPath) as TextureImporter; if (assetRule.SelectiveMode) { SerializedObject ruleImporterSO = new SerializedObject(ruleTexImporter); SerializedObject affectedAssetImporterSO = new SerializedObject(affectedAssetTexImporter); CopySelectiveProperties(affectedAssetImporterSO, ruleImporterSO, assetRule); } else { EditorUtility.CopySerialized(ruleTexImporter, affectedAssetTexImporter); } affectedAssetTexImporter.userData = ""; affectedAssetTexImporter.SaveAndReimport(); break; case AssetType.Model: ModelImporter ruleModelImporter = AssetImporter.GetAtPath(ruleAssetPath) as ModelImporter; ModelImporter affectedAssetModelImporter = AssetImporter.GetAtPath(affectedAssetPath) as ModelImporter; if (assetRule.SelectiveMode) { SerializedObject ruleImporterSO = new SerializedObject(ruleModelImporter); SerializedObject affectedAssetImporterSO = new SerializedObject(affectedAssetModelImporter); CopySelectiveProperties(affectedAssetImporterSO, ruleImporterSO, assetRule); } else { EditorUtility.CopySerialized(ruleModelImporter, affectedAssetModelImporter); } affectedAssetModelImporter.userData = ""; affectedAssetModelImporter.SaveAndReimport(); break; case AssetType.Audio: AudioImporter ruleAudioImporter = AssetImporter.GetAtPath(ruleAssetPath) as AudioImporter; AudioImporter affectedAssetAudioImporter = AssetImporter.GetAtPath(affectedAssetPath) as AudioImporter; if (assetRule.SelectiveMode) { SerializedObject ruleImporterSO = new SerializedObject(ruleAudioImporter); SerializedObject affectedAssetImporterSO = new SerializedObject(affectedAssetAudioImporter); CopySelectiveProperties(affectedAssetImporterSO, ruleImporterSO, assetRule); } else { EditorUtility.CopySerialized(ruleAudioImporter, affectedAssetAudioImporter); } affectedAssetAudioImporter.userData = ""; affectedAssetAudioImporter.SaveAndReimport(); break; case AssetType.Folder: break; default: throw new ArgumentOutOfRangeException(); } data.conforms = true; }
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(); }