public DeAudioClipData(DeAudioGroupId groupId, float volume = 1, float pitch = 1, bool loop = false) { this.groupId = groupId; this.volume = volume; this.pitch = pitch; this.loop = loop; }
/// <summary>Unlocks all <see cref="DeAudioSource"/> instances for the given group</summary> public static void Unlock(DeAudioGroupId groupId) { DeAudioGroup group = GetAudioGroup(groupId); if (group != null) { group.Unlock(); } }
/// <summary>Changes the pitch for the given group's existing sources</summary> public static void ChangePitch(DeAudioGroupId groupId, float pitch) { DeAudioGroup group = GetAudioGroup(groupId); if (group != null) { group.ChangePitch(pitch); } }
/// <summary>Sets the volume for the given group</summary> public static void SetVolume(DeAudioGroupId groupId, float volume) { DeAudioGroup group = GetAudioGroup(groupId); if (group != null) { group.SetVolume(volume); } }
/// <summary>Resumes all paused sounds for the given group</summary> /// <param name="groupId">Group ID</param> /// <param name="volume">If >=0 also sets the group volume, otherwise leaves as it was</param> public static void Resume(DeAudioGroupId groupId, float volume = -1) { DeAudioGroup group = GetAudioGroup(groupId); if (group != null) { group.Resume(volume); } }
/// <summary>Pauses all sounds for the given group</summary> public static void Pause(DeAudioGroupId groupId) { DeAudioGroup group = GetAudioGroup(groupId); if (group != null) { group.Pause(); } }
/// <summary>Stops all paused sounds for the given group</summary> public static void StopAllPaused(DeAudioGroupId groupId) { DeAudioGroup group = GetAudioGroup(groupId); if (group != null) { group.StopAllPaused(); } }
static void FadeSourcesTo(DeAudioGroupId groupId, float to, float duration, bool ignoreTimeScale, FadeBehaviour onCompleteBehaviour, TweenCallback onComplete) { DeAudioGroup group = GetAudioGroup(groupId); if (group != null) { group.FadeSourcesTo(to, duration, ignoreTimeScale, onCompleteBehaviour, onComplete); } }
public DeAudioGroup(DeAudioGroupId id, float volume, int maxSources = -1, int preallocate = 0, bool recycle = true, AudioMixerGroup mixerGroup = null) { this.id = id; this.volume = volume; this.maxSources = maxSources; this.preallocate = preallocate; this.recycle = recycle; this.mixerGroup = mixerGroup; }
/// <summary> /// Returns the AudioMixerGroup for <see cref="DeAudioGroup"/> with the given ID, or null if there is none /// </summary> public static AudioMixerGroup GetMixerGroup(DeAudioGroupId groupId) { DeAudioGroup g = GetAudioGroup(groupId); if (g == null) { return(null); } return(g.mixerGroup); }
/// <summary> /// Fades out then stops all sources in the given group, while starting the given clip with a fade-in effect. /// <para>Returns the <see cref="DeAudioSource"/> instance used to play, or NULL if the clip couldn't be played</para> /// </summary> public static DeAudioSource Crossfade(DeAudioGroupId groupId, AudioClip clip, float volume = 1, float pitch = 1, bool loop = false, float fadeDuration = 1.5f, bool ignoreTimeScale = true, FadeBehaviour onfadeOutBehaviour = FadeBehaviour.Stop, TweenCallback onComplete = null) { DeAudioGroup group = GetAudioGroup(groupId); if (group == null) { Debug.LogWarning(LogPrefix + "Crossfade can't happend and clip can't be played because no group with the given groupId (" + groupId + ") was created"); return(null); } return(group.Crossfade(clip, volume, pitch, loop, fadeDuration, ignoreTimeScale, onfadeOutBehaviour, onComplete)); }
/// <summary> /// Plays the given sound with the given options, using the given group id, and from the given time. /// A <see cref="DeAudioGroup"/> with the given ID must exist in order for the sound to actually play. /// <para>Returns the <see cref="DeAudioSource"/> instance used to play, or NULL if the clip couldn't be played</para> /// </summary> public static DeAudioSource PlayFrom(DeAudioGroupId groupId, AudioClip clip, float fromTime, float volume = 1, float pitch = 1, bool loop = false) { DeAudioGroup group = GetAudioGroup(groupId); if (group == null) { Debug.LogWarning(LogPrefix + "Clip can't be played because no group with the given groupId (" + groupId + ") was created"); return(null); } return(group.PlayFrom(clip, fromTime, volume, pitch, loop)); }
/// <summary> /// Returns the <see cref="DeAudioGroup"/> with the given ID, or NULL if there is none /// </summary> public static DeAudioGroup GetAudioGroup(DeAudioGroupId groupId) { int len = audioGroups.Length; for (int i = 0; i < len; ++i) { DeAudioGroup g = audioGroups[i]; if (g.id == groupId) { return(g); } } return(null); }
void OnEnable() { _src = target as DeAudioManager; DeAudioEditorUtils.CheckForDuplicateAudioGroupIds(_src.fooAudioGroups, _duplicateGroupIds); float lineH = EditorGUIUtility.singleLineHeight; float listVSpacer = 2f; _audioGroupsList = new ReorderableList(serializedObject, serializedObject.FindProperty("fooAudioGroups"), true, true, true, true); _audioGroupsList.elementHeight = lineH * 5 + listVSpacer * 4 + 10; _audioGroupsList.drawHeaderCallback = rect => { GUI.Label(rect, "DeAudioGroups", DeGUI.styles.label.bold); }; _audioGroupsList.onChangedCallback = list => { _requiresDuplicateCheck = true; }; _audioGroupsList.onAddCallback = list => { // Force volume to 1, max sources to -1 and recycle to true ReorderableList.defaultBehaviours.DoAddButton(list); int addedIndex = list.serializedProperty.arraySize - 1; SerializedProperty element = list.serializedProperty.GetArrayElementAtIndex(addedIndex); element.FindPropertyRelative("mixerGroup").objectReferenceValue = null; element.FindPropertyRelative("id").enumValueIndex = 0; element.FindPropertyRelative("fooVolume").floatValue = 1; element.FindPropertyRelative("maxSources").intValue = -1; element.FindPropertyRelative("recycle").boolValue = true; }; _audioGroupsList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { if (_requiresDuplicateCheck && Event.current.type == EventType.Repaint) { DeAudioEditorUtils.CheckForDuplicateAudioGroupIds(_src.fooAudioGroups, _duplicateGroupIds); _requiresDuplicateCheck = false; } bool hasDuplicateGroupIds = _duplicateGroupIds.Count > 0; EditorGUIUtility.labelWidth = 86; float ry = rect.y + 2; DeAudioGroup item = _src.fooAudioGroups[index]; GUI.color = item.mixerGroup == null ? Color.white : Color.green; AudioMixerGroup prevMixerGroup = item.mixerGroup; item.mixerGroup = EditorGUI.ObjectField(new Rect(rect.x, ry, rect.width, lineH), "MixerGroup", item.mixerGroup, typeof(AudioMixerGroup), false) as AudioMixerGroup; if (item.mixerGroup != prevMixerGroup) { DeAudioEditorUtils.CheckForDuplicateAudioGroupIds(_src.fooAudioGroups, _duplicateGroupIds); } GUI.color = Color.white; ry += lineH + listVSpacer; DeAudioGroupId prevId = item.id; GUI.color = hasDuplicateGroupIds && _duplicateGroupIds.Contains(item.id) ? Color.red : Color.white; item.id = (DeAudioGroupId)EditorGUI.EnumPopup(new Rect(rect.x, ry, rect.width, lineH), "Id (univocal)", item.id); GUI.color = Color.white; if (item.id != prevId) { DeAudioEditorUtils.CheckForDuplicateAudioGroupIds(_src.fooAudioGroups, _duplicateGroupIds); } ry += lineH + listVSpacer; item.fooVolume = EditorGUI.Slider(new Rect(rect.x, ry, rect.width, lineH), "Volume", item.fooVolume, 0, 1); ry += lineH + listVSpacer; item.maxSources = EditorGUI.IntSlider(new Rect(rect.x, ry, rect.width, lineH), "Max Sources", item.maxSources, -1, 100); ry += lineH + listVSpacer; item.recycle = EditorGUI.Toggle(new Rect(rect.x, ry, 120, lineH), new GUIContent(" Recycle", "If toggled, when max sources are reached and no free one is available the oldest one will be reused. If untoggled the new audio won't play."), item.recycle); EditorGUI.BeginDisabledGroup(item.maxSources == 0); EditorGUIUtility.labelWidth = 76; item.preallocate = EditorGUI.IntSlider(new Rect(rect.x + 120, ry, rect.width - 120, lineH), new GUIContent("Pre-allocate", "Allocates the given sources at startup."), item.preallocate, 0, item.maxSources >= 0 ? item.maxSources : 100); EditorGUI.EndDisabledGroup(); }; }
public DeAudioClipData(DeAudioGroupId groupId, bool loop) { this.groupId = groupId; this.loop = loop; }
public static DeAudioClipData DeAudioClip(Rect rect, GUIContent label, DeAudioClipData value, bool allowGroupChange = true, DeAudioClipGUIMode mode = DeAudioClipGUIMode.Full) { Styles.Init(); bool hasGroup = false; bool hasPlayStopButtonsInFirstRow = false; bool hasPlayStopButtonsInSecondRow = false; bool hasVolume = false; bool hasLoopInSecondRow = false; bool hasLoopInThirdRow = false; bool hasPitch = false; if (mode != DeAudioClipGUIMode.ClipOnly) { if (mode != DeAudioClipGUIMode.CompactPreviewOnly && mode != DeAudioClipGUIMode.FullNoGroup) { hasGroup = true; } switch (mode) { case DeAudioClipGUIMode.CompactPreviewOnly: case DeAudioClipGUIMode.CompactWithGroupAndPreview: hasPlayStopButtonsInFirstRow = true; break; case DeAudioClipGUIMode.VolumeWithPreview: case DeAudioClipGUIMode.VolumeAndLoopsWithPreview: case DeAudioClipGUIMode.FullNoGroup: case DeAudioClipGUIMode.Full: hasVolume = true; hasPlayStopButtonsInSecondRow = true; if (mode == DeAudioClipGUIMode.VolumeAndLoopsWithPreview) { hasLoopInSecondRow = true; } if (mode == DeAudioClipGUIMode.FullNoGroup || mode == DeAudioClipGUIMode.Full) { hasPitch = true; hasLoopInThirdRow = true; } break; } } Rect lineR = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight); // First line if (hasPlayStopButtonsInFirstRow) { Rect btStopR = new Rect(lineR.xMax - _ControlButtonW, lineR.y, _ControlButtonW, lineR.height); Rect btPlayR = new Rect(btStopR.x - _ControlButtonW, btStopR.y, btStopR.width, btStopR.height); lineR.width -= _ControlButtonW * 2; PlayButton(btPlayR, value); StopButton(btStopR); } if (hasGroup) { Rect groupR = new Rect(lineR.xMax - _GroupW, lineR.y, _GroupW, lineR.height); lineR.width -= groupR.width; using (new EditorGUI.DisabledGroupScope(!allowGroupChange)) { DeAudioGroupId newGroupId = (DeAudioGroupId)EditorGUI.EnumPopup(groupR, value.groupId); if (allowGroupChange) { value.groupId = newGroupId; } } } Rect clipR = lineR; value.clip = label.text == "" ? EditorGUI.ObjectField(clipR, value.clip, typeof(AudioClip), false) as AudioClip : EditorGUI.ObjectField(clipR, label, value.clip, typeof(AudioClip), false) as AudioClip; // Second line lineR.y = lineR.yMax + VSpace; lineR.width = rect.width; if (hasPlayStopButtonsInSecondRow) { Rect btStopR = new Rect(lineR.xMax - _ControlButtonW, lineR.y, _ControlButtonW, lineR.height); Rect btPlayR = new Rect(btStopR.x - _ControlButtonW, btStopR.y, btStopR.width, btStopR.height); lineR.width -= _ControlButtonW * 2; PlayButton(btPlayR, value); StopButton(btStopR); } if (hasLoopInSecondRow) { Rect loopR = new Rect(lineR.xMax - _LoopToggleW, lineR.y, _LoopToggleW, lineR.height); lineR.width -= loopR.width; LoopToggle(loopR, value); } if (hasVolume) { Rect volumeR = lineR; value.volume = EditorGUI.Slider(volumeR, "└ Volume", value.volume, 0, 1); } // Third line lineR.y = lineR.yMax + VSpace; lineR.width = rect.width; if (hasLoopInThirdRow) { Rect loopR = new Rect(lineR.xMax - _LoopToggleW, lineR.y, _LoopToggleW, lineR.height); lineR.width -= loopR.width; LoopToggle(loopR, value); } if (hasPitch) { Rect pitchR = lineR; value.pitch = EditorGUI.Slider(pitchR, "└ Pitch", value.pitch, 0, 3); } return(value); }
/// <summary>Starts playing the given clip with a fade-in volume effect</summary> public static void FadeIn(DeAudioGroupId groupId, AudioClip clip, float duration = 1.5f, bool ignoreTimeScale = true, TweenCallback onComplete = null) { Play(groupId, clip).FadeFrom(0, duration, ignoreTimeScale, onComplete); }
public DeAudioGroup(DeAudioGroupId id) { this.id = id; }
/// <summary>Fades the volume of each source in the given group (not the given group's volume) to the given value</summary> public static void FadeSourcesTo(DeAudioGroupId groupId, float to, float duration = 1.5f, bool ignoreTimeScale = true, TweenCallback onComplete = null) { FadeSourcesTo(groupId, to, duration, ignoreTimeScale, FadeBehaviour.None, onComplete); }
/// <summary>Fades out the volume of each source in the given group (not the given group's volume)</summary> public static void FadeSourcesOut(DeAudioGroupId groupId, float duration = 1.5f, bool ignoreTimeScale = true, FadeBehaviour onCompleteBehaviour = FadeBehaviour.Stop, TweenCallback onComplete = null) { FadeSourcesTo(groupId, 0, duration, ignoreTimeScale, onCompleteBehaviour, onComplete); }
/// <summary> /// Plays the given sound with the given options and using the given group id. /// A <see cref="DeAudioGroup"/> with the given ID must exist in order for the sound to actually play. /// <para>Returns the <see cref="DeAudioSource"/> instance used to play, or NULL if the clip couldn't be played</para> /// </summary> public static DeAudioSource Play(DeAudioGroupId groupId, AudioClip clip, float volume = 1, float pitch = 1, bool loop = false) { return(PlayFrom(groupId, clip, 0, volume, pitch, loop)); }