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); }
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 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); }
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); }
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; }
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); }
static bool IsAlreadySetLongAudio(AudioImporter ai, AudioImporterSampleSettings ais) { bool isSet = false; bool isOverride = ai.ContainsSampleSettingsOverride(Standalone); if (ais.loadType == LongAudio && ai.loadInBackground && isOverride) { isSet = true; } return(isSet); }
/// <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; }
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); }
/// <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; }