private void DrawSoundDatabaseDropZone(SoundDatabase soundDatabase) { GUILayout.Label(GUIContent.none, GUILayout.ExpandWidth(true), GUILayout.Height(0)); Rect lastRect = GUILayoutUtility.GetLastRect(); var dropRect = new Rect(lastRect.x + DGUI.Properties.Space(), lastRect.y - 2, DGUI.Properties.DefaultFieldWidth * 5, DGUI.Properties.SingleLineHeight); //calculate rect bool containsMouse = dropRect.Contains(Event.current.mousePosition); if (containsMouse) { DGUI.Colors.SetNormalGUIColorAlpha(); switch (Event.current.type) { case EventType.DragUpdated: bool containsAudioClip = DragAndDrop.objectReferences.OfType <AudioClip>().Any(); DragAndDrop.visualMode = containsAudioClip ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; Event.current.Use(); Repaint(); break; case EventType.DragPerform: IEnumerable <AudioClip> audioClips = DragAndDrop.objectReferences.OfType <AudioClip>(); bool undoRecorded = false; foreach (AudioClip audioClip in audioClips) { if (!undoRecorded) { DoozyUtils.UndoRecordObject(soundDatabase, UILabels.AddSounds); undoRecorded = true; } SoundGroupData soundGroupData = soundDatabase.Add(audioClip.name, false, false); soundGroupData.Sounds.Add(new AudioData(audioClip)); soundGroupData.SetDirty(false); soundDatabase.SetDirty(false); m_needsSave = true; } Event.current.Use(); Repaint(); break; } } DGUI.Doozy.DrawDropZone(dropRect, containsMouse); GUILayout.Space(dropRect.width); }
private void DrawViewSoundySoundDatabases(AnimBool searchEnabled) { bool foundNullReference = false; foreach (SoundDatabase soundDatabase in SoundyDatabase.SoundDatabases) { if (soundDatabase == null) { foundNullReference = true; break; } AnimBool soundDatabaseAnimBool = GetSoundDatabaseAnimBool(soundDatabase); AnimBool renameSoundDatabaseAnimBool = GetAnimBool(RENAME_SOUND_DATABASE); bool isGeneralSoundDatabase = soundDatabase.DatabaseName.Equals(SoundyManager.GENERAL); bool soundDatabaseContainsSearchedSound = false; bool renamingThisDatabase = !searchEnabled.target && m_soundDatabaseBeingRenamed == soundDatabase; bool databaseHasIssues = soundDatabase.HasSoundsWithMissingAudioClips; //database issues check ColorName viewColorName = CurrentViewColorName; ColorName mixerColorName = soundDatabase.OutputAudioMixerGroup != null ? viewColorName : DGUI.Colors.DisabledTextColorName; GUILayout.BeginHorizontal(); { DrawViewHorizontalPadding(); GUILayout.BeginVertical(); { GUILayout.BeginHorizontal(); { bool enabledState = GUI.enabled; GUI.enabled = !(renameSoundDatabaseAnimBool.target && renamingThisDatabase) && !searchEnabled.target; //do not allow the dev to use this button if THIS database is being renamed or a search is happening { GUILayout.BeginVertical(GUILayout.Height(BarHeight)); { if (DGUI.Bar.Draw(soundDatabase.DatabaseName, BAR_SIZE, DGUI.Bar.Caret.CaretType.Caret, viewColorName, soundDatabaseAnimBool)) //database BAR { if (Selection.activeObject != null && Selection.activeObject is SoundGroupData) { Selection.activeObject = null; } } GUILayout.Space(-BarHeight - DGUI.Properties.Space()); if (soundDatabase.OutputAudioMixerGroup == null) { DGUI.Colors.SetDisabledGUIColorAlpha(); } float barIconSize = BarHeight * 0.6f; SoundDatabase database = soundDatabase; DGUI.Line.Draw(false, () => { GUILayout.FlexibleSpace(); DGUI.Icon.Draw(Styles.GetStyle(Styles.StyleName.IconAudioMixerGroup), barIconSize, BarHeight, mixerColorName); //mixer icon if (database.OutputAudioMixerGroup != null) { GUILayout.Space(DGUI.Properties.Space(2)); DGUI.Label.Draw(database.OutputAudioMixerGroup.name + " (" + database.OutputAudioMixerGroup.audioMixer.name + ")", Size.S, mixerColorName, BarHeight); //mixer label } if (databaseHasIssues) { GUILayout.Space(DGUI.Properties.Space(4)); DGUI.Icon.Draw(Styles.GetStyle(Styles.StyleName.IconError), barIconSize, BarHeight, Color.red); } GUILayout.Space(DGUI.Properties.Space(2)); }); GUI.color = InitialGUIColor; } GUILayout.EndVertical(); } GUI.enabled = enabledState; if (!isGeneralSoundDatabase) { if (!searchEnabled.target && soundDatabaseAnimBool.faded > 0.05f && renameSoundDatabaseAnimBool.faded < 0.5f) { DGUI.AlphaGroup.Begin(soundDatabaseAnimBool.faded * (1 - renameSoundDatabaseAnimBool.faded)); GUILayout.Space(DGUI.Properties.Space() * soundDatabaseAnimBool.faded * (1 - renameSoundDatabaseAnimBool.faded)); if (DGUI.Button.Draw(DGUI.Properties.Labels.Rename, Size.S, TextAlign.Center, viewColorName, true, BarHeight, 80 * soundDatabaseAnimBool.faded * (1 - renameSoundDatabaseAnimBool.faded)) || renamingThisDatabase && Event.current.keyCode == KeyCode.Escape && Event.current.type == EventType.KeyUp) //rename database button { if (!renamingThisDatabase && EditorUtility.DisplayDialog(UILabels.RenameSoundDatabase + " '" + soundDatabase.DatabaseName + "'", UILabels.RenameSoundDatabaseDialogMessage + "\n\n" + UILabels.YouAreResponsibleToUpdateYourCode, UILabels.Continue, UILabels.Cancel)) { StartRenameSoundDatabase(soundDatabase); Instance.Focus(); } else { ResetRenameSoundDatabase(); } } if (DGUI.Button.IconButton.Cancel(BarHeight)) //delete database button { SoundyDatabase.DeleteDatabase(soundDatabase); break; } DGUI.AlphaGroup.End(); } } } GUILayout.EndHorizontal(); GUILayout.Space(DGUI.Properties.Space()); if (DGUI.FadeOut.Begin(searchEnabled.target ? 1 : soundDatabaseAnimBool.faded)) { GUILayout.BeginVertical(); //RENAME DATABASE if (renamingThisDatabase) { if (DGUI.FadeOut.Begin(renameSoundDatabaseAnimBool.faded, false)) { GUILayout.BeginVertical(); { GUILayout.Space(DGUI.Properties.Space() * renameSoundDatabaseAnimBool.faded); GUILayout.BeginHorizontal(GUILayout.Height(DGUI.Properties.SingleLineHeight + DGUI.Properties.Space(2))); { DrawDefaultViewHorizontalSpacing(); GUI.color = DGUI.Colors.BackgroundColor(RENAME_COLOR_NAME); DGUI.Label.Draw(UILabels.RenameTo, Size.S, DGUI.Properties.SingleLineHeight + DGUI.Properties.Space(2)); //rename to label GUI.SetNextControlName(RENAME); m_newSoundDatabaseName = EditorGUILayout.TextField(GUIContent.none, m_newSoundDatabaseName); //rename to field GUI.color = InitialGUIColor; if (DGUI.Button.IconButton.Ok() || Event.current.keyCode == KeyCode.Return && Event.current.type == EventType.KeyUp) //rename OK button { Instance.Focus(); if (SoundyDatabase.RenameSoundDatabase(soundDatabase, m_newSoundDatabaseName)) { GetSoundDatabaseAnimBool(m_newSoundDatabaseName).value = true; ResetRenameSoundDatabase(); break; } } if (DGUI.Button.IconButton.Cancel() || Event.current.keyCode == KeyCode.Escape && Event.current.type == EventType.KeyUp) //rename CANCEL button { ResetRenameSoundDatabase(); } EditorGUI.FocusTextInControl(RENAME); DrawDefaultViewHorizontalSpacing(); } GUILayout.EndHorizontal(); GUILayout.Space(DGUI.Properties.Space(4) * renameSoundDatabaseAnimBool.faded); } GUILayout.EndVertical(); GUI.color = InitialGUIColor; } DGUI.FadeOut.End(renameSoundDatabaseAnimBool, false); } GUILayout.Space(DGUI.Properties.Space() * soundDatabaseAnimBool.faded); if (!searchEnabled.target) { float barIconSize = DGUI.Properties.SingleLineHeight * 0.8f; float barIconRowHeight = DGUI.Properties.SingleLineHeight - 1; GUILayout.BeginHorizontal(); { SoundDatabase database = soundDatabase; DGUI.Line.Draw(true, mixerColorName, () => { if (database.OutputAudioMixerGroup == null) { DGUI.Colors.SetDisabledGUIColorAlpha(); } DGUI.Icon.Draw(Styles.GetStyle(Styles.StyleName.IconAudioMixerGroup), barIconSize, barIconRowHeight, mixerColorName); //mixer icon GUILayout.Space(DGUI.Properties.Space()); DGUI.Label.Draw(UILabels.OutputMixerGroup, Size.S, mixerColorName, DGUI.Properties.SingleLineHeight); //mixer label GUI.color = InitialGUIColor; AudioMixerGroup outputAudioMixerGroup = database.OutputAudioMixerGroup; GUI.color = DGUI.Colors.GetDColor(mixerColorName).Light.WithAlpha(GUI.color.a); GUILayout.BeginVertical(GUILayout.Height(DGUI.Properties.SingleLineHeight)); { GUILayout.Space(0f); EditorGUI.BeginChangeCheck(); outputAudioMixerGroup = (AudioMixerGroup)EditorGUILayout.ObjectField(GUIContent.none, outputAudioMixerGroup, typeof(AudioMixerGroup), false); //mixer field if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(database, "Update AudioMixerGroup"); database.OutputAudioMixerGroup = outputAudioMixerGroup; database.SetDirty(true); } } GUILayout.EndVertical(); GUI.color = InitialGUIColor; }); GUILayout.Space(DGUI.Button.IconButton.Width + DGUI.Properties.Space(4)); } GUILayout.EndHorizontal(); } GUILayout.Space(DGUI.Properties.Space(2) * soundDatabaseAnimBool.faded); float lineHeight = DGUI.Properties.SingleLineHeight; float iconSize = lineHeight * 0.8f; GUILayout.Label(GUIContent.none, GUILayout.ExpandWidth(true), GUILayout.Height(0)); Rect rect = GUILayoutUtility.GetLastRect(); float x; float y = rect.y; float totalWidth = rect.width; float buttonAndPlayerWidth = rect.width - DGUI.Properties.Space(6) - iconSize - DGUI.Button.IconButton.Width; float buttonWidth = buttonAndPlayerWidth * 0.4f; float playerWidth = buttonAndPlayerWidth - buttonWidth; foreach (SoundGroupData soundGroupData in soundDatabase.Database) { if (searchEnabled.target) { if (!Regex.IsMatch(soundGroupData.SoundName, m_soundySearchPattern, RegexOptions.IgnoreCase)) //regex search check { if (!m_soundySearchAudioClipNames) { continue; } if (soundGroupData.Sounds == null || soundGroupData.Sounds.Count == 0) { continue; } bool foundAudioClipMatch = false; foreach (AudioData audioData in soundGroupData.Sounds) { if (audioData == null || audioData.AudioClip == null) { continue; } if (!Regex.IsMatch(audioData.AudioClip.name, m_soundySearchPattern, RegexOptions.IgnoreCase)) { continue; } foundAudioClipMatch = true; break; } if (!foundAudioClipMatch) { continue; } } soundDatabaseContainsSearchedSound = true; } //draw check - if the item was scrolled out of view (up or down) -> do not draw it bool drawItem = y > m_scrollPosition.y + 16 || y < m_scrollPosition.y + ViewRect.height - 16; if (!drawItem) { continue; } bool removedEntry = false; GUILayout.Space(DGUI.Properties.Space() * soundDatabaseAnimBool.faded); GUILayout.Label(GUIContent.none, GUILayout.ExpandWidth(true), GUILayout.Height(lineHeight)); x = rect.x; y += DGUI.Properties.Space() * soundDatabaseAnimBool.faded; bool noSound = soundGroupData.SoundName.Equals(SoundyManager.NO_SOUND); //is no sound check bool isSelected = Selection.activeObject == soundGroupData; //selected check bool hasIssues = !noSound && soundGroupData.HasMissingAudioClips; //has issues check bool enabledState = GUI.enabled; GUI.enabled = !noSound; { SoundyAudioPlayer.Player player = SoundyAudioPlayer.GetPlayer(soundGroupData, soundDatabase.OutputAudioMixerGroup); //player reference ColorName buttonColorName = isSelected ? hasIssues ? ColorName.Red : CurrentViewColorName : DGUI.Colors.DisabledBackgroundColorName; ColorName buttonTextColorName = hasIssues ? ColorName.Red : CurrentViewColorName; // if (i % 2 == 0) if (player.IsPlaying) { var backgroundRect = new Rect(x - DGUI.Properties.Space(2), y - DGUI.Properties.Space(), totalWidth + DGUI.Properties.Space(4), lineHeight + DGUI.Properties.Space(2)); GUI.color = DGUI.Colors.BackgroundColor(buttonColorName).WithAlpha(0.6f); GUI.Label(backgroundRect, GUIContent.none, Styles.GetStyle(Styles.StyleName.BackgroundRound)); GUI.color = InitialGUIColor; } var iconRect = new Rect(x, y + (lineHeight - iconSize) / 2, iconSize, iconSize); if (!player.IsPlaying) { GUI.color = GUI.color.WithAlpha(DGUI.Utility.IsProSkin ? 0.4f : 0.6f); } DGUI.Icon.Draw(iconRect, Styles.GetStyle(noSound || hasIssues ? Styles.StyleName.IconMuteSound : Styles.StyleName.IconSound), DGUI.Colors.TextColor(hasIssues ? ColorName.Red : buttonTextColorName)); //speaker icon GUI.color = InitialGUIColor; x += iconSize; x += DGUI.Properties.Space(2); var buttonRect = new Rect(x, y - DGUI.Properties.Space(), buttonWidth, lineHeight + DGUI.Properties.Space(2)); if (DGUI.Button.Draw(buttonRect, soundGroupData.SoundName, Size.S, TextAlign.Left, buttonColorName, buttonTextColorName, isSelected)) //select button { Selection.activeObject = soundGroupData; } if (hasIssues) { var errorIconRect = new Rect(buttonRect.xMax - iconSize - DGUI.Properties.Space(2), buttonRect.y + (buttonRect.height - iconSize) / 2, iconSize, iconSize); DGUI.Icon.Draw(errorIconRect, Styles.GetStyle(Styles.StyleName.IconError), Color.red); //issues icon } x += buttonWidth; x += DGUI.Properties.Space(2); var playerRect = new Rect(x, y, playerWidth, lineHeight); player.DrawPlayer(playerRect, buttonTextColorName); x += playerWidth; x += DGUI.Properties.Space(2); var deleteButtonRect = new Rect(x, y, DGUI.Button.IconButton.Width, DGUI.Button.IconButton.Height); if (DGUI.Button.IconButton.Minus(deleteButtonRect)) { bool wasSelected = Selection.activeObject == soundGroupData; if (soundDatabase.Remove(soundGroupData, true)) { if (wasSelected) { Selection.activeObject = null; } soundDatabase.SetDirty(true); if (player.IsPlaying) { player.Stop(); } removedEntry = true; } } y += lineHeight; y += DGUI.Properties.Space(2) * soundDatabaseAnimBool.faded; } GUI.enabled = enabledState; GUILayout.Space(DGUI.Properties.Space() * soundDatabaseAnimBool.faded); if (removedEntry) { break; } } GUILayout.Space(DGUI.Properties.Space() * soundDatabaseAnimBool.faded); if (!searchEnabled.target) { GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); DrawSoundDatabaseDropZone(soundDatabase); GUILayout.Space(DGUI.Properties.Space()); if (DGUI.Button.IconButton.Plus()) { Selection.activeObject = soundDatabase.Add(SoundyManager.NEW_SOUND_GROUP, true, true); } } GUILayout.EndHorizontal(); } GUI.enabled = !(GetAnimBool(RENAME_SOUND_DATABASE).target&& renamingThisDatabase); GUILayout.EndVertical(); } DGUI.FadeOut.End(searchEnabled.target ? 1 : soundDatabaseAnimBool.faded); if (searchEnabled.target) { if (soundDatabaseContainsSearchedSound && !m_soundDatabasesWithSearchedSoundNames.Contains(soundDatabase)) { m_soundDatabasesWithSearchedSoundNames.Add(soundDatabase); soundDatabaseAnimBool.target = true; } else if (!soundDatabaseContainsSearchedSound && m_soundDatabasesWithSearchedSoundNames.Contains(soundDatabase)) { m_soundDatabasesWithSearchedSoundNames.Remove(soundDatabase); soundDatabaseAnimBool.target = false; } } } GUILayout.EndVertical(); DrawViewHorizontalPadding(); } GUILayout.EndHorizontal(); } if (foundNullReference) { SoundyDatabase.RefreshDatabase(false); } }