void DrawRuntimeSourcesFor(DeAudioGroup group) { Color trueVolumeColor = new Color(0.18f, 0.91f, 0f); Color volumeColor = new Color(0.62f, 0.83f, 0f); Color truePitchColor = new Color(0.96f, 0.15f, 0.97f); Color pitchColor = new Color(0.67f, 0.32f, 0.99f); Color timeColor = new Color(0f, 0.61f, 1f); int len = group.sources.Count; for (int i = 0; i < len; ++i) { // Sources volume and play time DeAudioSource s = group.sources[i]; if (!s.isPlaying) { continue; } _runtimeStrb.Length = 0; _runtimeStrb.Append("└ ").Append(s.clip.name); if (s.locked) { _runtimeStrb.Append(" [LOCKED]"); } if (s.loop) { _runtimeStrb.Append(" [loop]"); } GUILayout.Label(_runtimeStrb.ToString()); // Volume DrawRuntimeSourceBar(volumeColor, s.unscaledVolume, null, s.volume, trueVolumeColor); // Pitch const float markerP = 1f / 3f; DrawRuntimeSourceBar(pitchColor, s.unscaledPitch / 3, markerP, s.pitch / 3, truePitchColor); // Elapsed time float elapsed = s.audioSource.time / s.clip.length; if (elapsed > 1) { elapsed = 1; } DrawRuntimeSourceBar(timeColor, elapsed); } }
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 DeAudioEventArgs(DeAudioEventType type, DeAudioGroup audioGroup, DeAudioSource source) { this.type = type; this.audioGroup = audioGroup; this.source = source; }