static void OnPreprocessSoundClip(string assetPath, AudioImporter importer) { importer.loadInBackground = false; var standalone = new AudioImporterSampleSettings(); standalone.quality = 0.7f; standalone.loadType = AudioClipLoadType.DecompressOnLoad; standalone.compressionFormat = AudioCompressionFormat.PCM; standalone.sampleRateSetting = AudioSampleRateSetting.OptimizeSampleRate; importer.SetOverrideSampleSettings("Standalone", standalone); var iOS = new AudioImporterSampleSettings(); iOS.quality = 0.7f; iOS.loadType = AudioClipLoadType.DecompressOnLoad; iOS.compressionFormat = AudioCompressionFormat.MP3; iOS.sampleRateSetting = AudioSampleRateSetting.OptimizeSampleRate; importer.SetOverrideSampleSettings("iOS", iOS); var android = new AudioImporterSampleSettings(); android.quality = 0.7f; android.loadType = AudioClipLoadType.DecompressOnLoad; android.compressionFormat = AudioCompressionFormat.ADPCM; android.sampleRateSetting = AudioSampleRateSetting.OptimizeSampleRate; importer.SetOverrideSampleSettings("Android", android); }
static void OnPreprocessMusicClip(string assetPath, AudioImporter importer) { importer.loadInBackground = true; var standalone = new AudioImporterSampleSettings(); standalone.quality = 0.7f; standalone.loadType = AudioClipLoadType.Streaming; standalone.compressionFormat = AudioCompressionFormat.Vorbis; standalone.sampleRateSetting = AudioSampleRateSetting.OptimizeSampleRate; importer.SetOverrideSampleSettings("Standalone", standalone); var iOS = new AudioImporterSampleSettings(); iOS.quality = 0.7f; iOS.loadType = AudioClipLoadType.Streaming; iOS.compressionFormat = AudioCompressionFormat.MP3; iOS.sampleRateSetting = AudioSampleRateSetting.OptimizeSampleRate; importer.SetOverrideSampleSettings("iOS", iOS); var android = new AudioImporterSampleSettings(); android.quality = 0.7f; android.loadType = AudioClipLoadType.Streaming; android.compressionFormat = AudioCompressionFormat.Vorbis; android.sampleRateSetting = AudioSampleRateSetting.OptimizeSampleRate; importer.SetOverrideSampleSettings("Android", android); }
private void OnPreprocessAsset() { AudioImporter ai = assetImporter as AudioImporter; if (ai == null) { return; } AudioImporterSampleSettings set = new AudioImporterSampleSettings(); ai.loadInBackground = false; ai.preloadAudioData = true; ai.ambisonic = false; set.loadType = AudioClipLoadType.CompressedInMemory; set.sampleRateOverride = 44100; set.compressionFormat = AudioCompressionFormat.Vorbis; if (ai.assetPath.Contains("BGM")) { set.quality = 0.8f; ai.forceToMono = false; } else { set.quality = 0.6f; ai.forceToMono = true; } ai.SetOverrideSampleSettings("PC", set); ai.SetOverrideSampleSettings("iOS", set); ai.SetOverrideSampleSettings("Android", set); }
public override void ApplySettings(UnityEditor.AssetImporter assetImporter) { AudioImporter importer = assetImporter as AudioImporter; if (importer == null) { return; } importer.forceToMono = forceToMono; if (forceToMono) { //importer.normalize = normalize; } importer.loadInBackground = loadInBackground; importer.ambisonic = ambisonic; importer.preloadAudioData = preloadAudioData; AudioImporterSampleSettings sampleSettings = importer.defaultSampleSettings; sampleSettings.loadType = loadType; sampleSettings.compressionFormat = compressionFormat; sampleSettings.quality = quality; sampleSettings.sampleRateSetting = sampleRateSetting; sampleSettings.sampleRateOverride = (uint)sampleRate; importer.defaultSampleSettings = sampleSettings; importer.SetOverrideSampleSettings("Android", sampleSettings); importer.SetOverrideSampleSettings("iPhone", sampleSettings); //importer.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); }
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(); }
//============================================================================= // process //============================================================================= /// <summary> /// set importer /// </summary> private void ImportCustomAudio(CustomAudioImporter customImporter) { if (customImporter == null || !customImporter.IsEnable) { return; } AudioImporter audioImporter = assetImporter as AudioImporter; CustomAudioImporterSettingValue customSettings = customImporter.ImporterSetting; if (customSettings.ForceToMono.IsConfigurable) { audioImporter.forceToMono = customSettings.ForceToMono; } if (customSettings.LoadInBackGround.IsConfigurable) { audioImporter.loadInBackground = customSettings.LoadInBackGround; } #if UNITY_2017_1_OR_NEWER if (customSettings.Ambisonic.IsConfigurable) { audioImporter.ambisonic = customSettings.Ambisonic; } #endif if (customSettings.PreloadAudioData.IsConfigurable) { audioImporter.preloadAudioData = customSettings.PreloadAudioData; } audioImporter.defaultSampleSettings = SetCustomAudioSettings(customSettings); // override settings if (customImporter.OverrideForAndroidSetting.IsConfigurable) { audioImporter.SetOverrideSampleSettings("Android", SetCustomAudioSettings(customImporter.OverrideForAndroidSetting)); } else { audioImporter.ClearSampleSettingOverride("Android"); } if (customImporter.OverrideForiOSSetting.IsConfigurable) { audioImporter.SetOverrideSampleSettings("iOS", SetCustomAudioSettings(customImporter.OverrideForiOSSetting)); } else { audioImporter.ClearSampleSettingOverride("iOS"); } if (customImporter.IsLogger) { Debug.Log(string.Format("CustomAudioImporter : " + customImporter.Log + "\nProcessed : {0}", assetPath)); } }
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); }
/// <summary> /// 更改导入音频的格式 /// </summary> void OnPreprocessAudio() { if (IsAssetProcessed) { return; } IsAssetProcessed = true; AudioImporter audioImporter = (AudioImporter)assetImporter; if (audioImporter == null) { return; } AudioImporterSampleSettings sampleSetting = new AudioImporterSampleSettings(); sampleSetting.loadType = AudioClipLoadType.CompressedInMemory; sampleSetting.compressionFormat = AudioCompressionFormat.Vorbis; sampleSetting.quality = 0.01f;//1为100 //这种情况下可以改变默认Defalut下面的格式 audioImporter.defaultSampleSettings = sampleSetting; //这种情况下只会更改PC/IOS/Android下面的格式 bool successfullOverride = audioImporter.SetOverrideSampleSettings("PC", sampleSetting); //Debug.Log(successfullOverride); }
static void SetLongAudio(AudioImporter ai, AudioImporterSampleSettings ais) { ai.loadInBackground = true; ais.loadType = LongAudio; ai.defaultSampleSettings = ais; ai.SetOverrideSampleSettings(Standalone, ais); }
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; }
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; } }
void OnPreprocessAudio() { ImportProperties importProperties = (ImportProperties)AssetDatabase.LoadAssetAtPath("Assets/Prefabs/ImportProperties.prefab", typeof(ImportProperties)); if (importProperties && importProperties.enableCustomImportSetting) { AudioImporter audioImporter = assetImporter as AudioImporter; var a = audioImporter.defaultSampleSettings; a.compressionFormat = importProperties.audioCompressionFormat; a.sampleRateSetting = importProperties.audioSampleRateSetting; a.loadType = importProperties.audioClipLoadType; audioImporter.defaultSampleSettings = a; // Override Android Import Settings if (importProperties.overrideAudioForAndroid) { AudioImporterSampleSettings settings = new AudioImporterSampleSettings(); settings.compressionFormat = importProperties.audioCompressionFormatForAndroid; settings.sampleRateSetting = importProperties.audioSampleRateSettingForAndroid; settings.loadType = importProperties.audioClipLoadTypeForAndroid; audioImporter.SetOverrideSampleSettings("Android", settings); } } }
private void SetAudioImporterIOSSetting(AudioImporter audioImporter, AudioClipLoadType loadType) { audioImporter.SetOverrideSampleSettings("iOS", new AudioImporterSampleSettings { quality = AudioPreprocessorConfig.iosConfig.Quality, loadType = loadType }); }
/// <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 void SetAudioImporterStandaloneSetting(AudioImporter audioImporter, AudioClipLoadType loadType) { audioImporter.SetOverrideSampleSettings("Standalone", new AudioImporterSampleSettings { quality = AudioPreprocessorConfig.standaloneConfig.Quality, loadType = loadType }); }
/// <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); }
//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(); } }
// Apply settings Method which searches and adds all audio clips in an array, and for each clip, adds the settings, overrides it for the selected platform // and imports the newly applied asset again, therefore applying all the settings properly. static void ApplySettings(uint sampleRate, AudioCompressionFormat format, AudioClipLoadType loadType, string platform) { Object[] audioclips = GetSelectedAudioclips(); Selection.objects = new Object[0]; foreach (AudioClip audioclip in audioclips) { string path = AssetDatabase.GetAssetPath(audioclip); AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter; AudioImporterSampleSettings settings = audioImporter.defaultSampleSettings; settings.compressionFormat = format; settings.sampleRateSetting = AudioSampleRateSetting.OverrideSampleRate; settings.sampleRateOverride = sampleRate; settings.loadType = loadType; audioImporter.SetOverrideSampleSettings(platform, settings); AssetDatabase.ImportAsset(path); } }
//设置长音频格式 static void SetLongAudio(string path) { AudioImporter ai = AssetImporter.GetAtPath(path) as AudioImporter; if (ai != null) { AudioImporterSampleSettings ais = ai.defaultSampleSettings; ai.loadInBackground = true; ais.loadType = LongAudio; ai.defaultSampleSettings = ais; ai.SetOverrideSampleSettings(Standalone, ais); Debug.Log("处理的长音频===>" + path); } else { Debug.LogError("导入此路径的文件不是音频类型===>" + path); } }
private void OverwriteImportSettings(AudioImporter importer) { var reference = referenceImporter as AudioImporter; UnityEngine.Assertions.Assert.IsNotNull(reference); importer.defaultSampleSettings = reference.defaultSampleSettings; importer.forceToMono = reference.forceToMono; importer.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 (!importer.SetOverrideSampleSettings(platformName, setting)) { LogUtility.Logger.LogError("AudioImporter", string.Format("Failed to set override setting for {0}: {1}", platformName, importer.assetPath)); } } else { importer.ClearSampleSettingOverride(platformName); } } // 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 importer.loadInBackground = reference.loadInBackground; #endif #if UNITY_2017_1_OR_NEWER importer.ambisonic = reference.ambisonic; #endif }
private void ApplyAudioConfig(AudioImportSetting cfg) { AudioImporter importer = assetImporter as AudioImporter; Debug.Log(111); importer.forceToMono = cfg.ForceToMono; importer.loadInBackground = cfg.LoadInBackground; importer.preloadAudioData = cfg.PreloadAudioData; AudioImporterSampleSettings otherSettings = new AudioImporterSampleSettings() { compressionFormat = cfg.AudioCompressionFormat, loadType = cfg.AudioClipLoadType, quality = (float)cfg.AudioQuality / 100f, sampleRateSetting = cfg.SampleRateSetting, }; if (cfg.SampleRateSetting == AudioSampleRateSetting.OverrideSampleRate) { otherSettings.sampleRateOverride = (uint)cfg.SampleRateOverride; } importer.SetOverrideSampleSettings("Android", otherSettings); importer.defaultSampleSettings = otherSettings; }
/// <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; }
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; } }; }
private void SetAudioImporter(string path) { AudioImporter audio = AssetImporter.GetAtPath(path) as AudioImporter; if (audio == null) { Debug.LogError("not found audio path:" + path); return; } audio.forceToMono = false; audio.loadInBackground = false; audio.preloadAudioData = false; AudioImporterSampleSettings settingAndroid = new AudioImporterSampleSettings(); AudioImporterSampleSettings settingIphone = new AudioImporterSampleSettings(); AudioImporterSampleSettings settingStandalone = new AudioImporterSampleSettings(); if (path.Contains("/BGM/")) { settingAndroid.loadType = AudioClipLoadType.Streaming; settingIphone.loadType = AudioClipLoadType.Streaming; settingStandalone.loadType = AudioClipLoadType.Streaming; } else if (path.Contains("/Sounds/") || path.Contains("/Common/") || path.Contains("/MainMenu/") || path.Contains("/Battle/")) { settingAndroid.loadType = AudioClipLoadType.DecompressOnLoad; settingIphone.loadType = AudioClipLoadType.DecompressOnLoad; settingStandalone.loadType = AudioClipLoadType.DecompressOnLoad; } else { Debug.LogError("You can't put it in this folder! \n" + path); return; } if (path.Contains("/High/")) { settingAndroid.compressionFormat = AudioCompressionFormat.Vorbis; settingAndroid.quality = 1f; settingAndroid.sampleRateSetting = AudioSampleRateSetting.PreserveSampleRate; settingIphone.compressionFormat = AudioCompressionFormat.Vorbis; settingIphone.quality = 1f; settingIphone.sampleRateSetting = AudioSampleRateSetting.PreserveSampleRate; settingStandalone.compressionFormat = AudioCompressionFormat.Vorbis; settingStandalone.quality = 1f; settingStandalone.sampleRateSetting = AudioSampleRateSetting.PreserveSampleRate; } else if (path.Contains("/Middle/")) { settingAndroid.compressionFormat = AudioCompressionFormat.Vorbis; settingAndroid.quality = 0.5f; settingAndroid.sampleRateSetting = AudioSampleRateSetting.OptimizeSampleRate; settingIphone.compressionFormat = AudioCompressionFormat.Vorbis; settingIphone.quality = 0.5f; settingIphone.sampleRateSetting = AudioSampleRateSetting.OptimizeSampleRate; settingStandalone.compressionFormat = AudioCompressionFormat.Vorbis; settingStandalone.quality = 0.5f; settingStandalone.sampleRateSetting = AudioSampleRateSetting.OptimizeSampleRate; } else { settingAndroid.compressionFormat = AudioCompressionFormat.Vorbis; settingAndroid.quality = 0.01f; settingAndroid.sampleRateSetting = AudioSampleRateSetting.OverrideSampleRate; settingAndroid.sampleRateOverride = 11025; settingIphone.compressionFormat = AudioCompressionFormat.Vorbis; settingIphone.quality = 0.01f; settingIphone.sampleRateSetting = AudioSampleRateSetting.OverrideSampleRate; settingIphone.sampleRateOverride = 11025; settingStandalone.compressionFormat = AudioCompressionFormat.Vorbis; settingStandalone.quality = 0.01f; settingStandalone.sampleRateSetting = AudioSampleRateSetting.OverrideSampleRate; settingStandalone.sampleRateOverride = 11025; } audio.SetOverrideSampleSettings("Android", settingAndroid); audio.SetOverrideSampleSettings("iPhone", settingIphone); audio.SetOverrideSampleSettings("Standalone", settingStandalone); }
/// <summary> /// Attempt to apply the given settings to the asset found at the path /// </summary> /// <param name="assetPath">Path to the asset</param> /// <param name="importSettings">Settings to apply</param> public static void ApplyImportSettingsToAsset(string assetPath, ImportSettings importSettings) { if (importSettings != null) { AssetImporter importer = AssetImporter.GetAtPath(assetPath); #region Apply Texture Import Settings if (importer.GetType() == typeof(TextureImporter) && importSettings.UseTextureSettings == true) { TextureImporter textureImporter = (TextureImporter)importer; //User wants to override the Android texture settings, create the appropriate settings and override them for Android if (importSettings.OverrideAndroidTextureSettings == true) { TextureImporterPlatformSettings androidTextureSettings = new TextureImporterPlatformSettings() { name = "Android", maxTextureSize = (int)importSettings.AndroidMaxTextureSize, overridden = true }; textureImporter.SetPlatformTextureSettings(androidTextureSettings); } else { //Make sure to stop overriding the Android settings, if they're disabled textureImporter.ClearPlatformTextureSettings("Android"); } textureImporter.filterMode = importSettings.TetxureFilterMode; textureImporter.maxTextureSize = (int)importSettings.MaxTextureSize; textureImporter.anisoLevel = importSettings.FilterLevel; s_validAssetCount++; } #endregion #region Apply Audio Import Settings if (importer.GetType() == typeof(AudioImporter) && importSettings.UseAudioSettings == true) { AudioImporter audioImporter = (AudioImporter)importer; AudioImporterSampleSettings audioImportSettings = new AudioImporterSampleSettings() { sampleRateSetting = importSettings.AudioSampleRate, sampleRateOverride = (uint)importSettings.SampleRateOverride, compressionFormat = importSettings.CompressionFormat, loadType = importSettings.AudioLoadType }; //User wants to override the Android audio settings, create the appropriate settings and override them for Android if (importSettings.OverrideAndroidAudioSettings == true) { AudioImporterSampleSettings androidAudioImportSettings = new AudioImporterSampleSettings() { sampleRateSetting = importSettings.AndroidAudioSampleRate, sampleRateOverride = (uint)importSettings.AndroidSampleRateOverride, compressionFormat = importSettings.AndroidCompressionFormat, loadType = importSettings.AndroidAudioClipLoadType }; audioImporter.SetOverrideSampleSettings("Android", androidAudioImportSettings); } else { //Make sure to stop overriding the Android settings, if they're disabled audioImporter.ClearSampleSettingOverride("Android"); } audioImporter.defaultSampleSettings = audioImportSettings; s_validAssetCount++; } #endregion AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate); } else { Debug.Log($"No import settings found for asset { assetPath } "); } }
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(); }
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 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; }