Esempio n. 1
0
        private void DrawPlayer(Rect drawRect, float x, float y, bool hasSound, SoundyAudioPlayer.Player player, ColorName colorName)
        {
            const float iconSize = 12f;

            if (hasSound && player != null)
            {
                var playerRect = new Rect(x, y, drawRect.width - DGUI.Properties.Space(2), DGUI.Properties.SingleLineHeight + DGUI.Properties.Space(2));
                player.DrawPlayer(playerRect, colorName);
            }
            else
            {
                y += DGUI.Properties.Space() + 1;

                var     messageContent     = new GUIContent("Soundy Player - Not Available");
                Vector2 messageContentSize = DGUI.Label.Style(Size.S).CalcSize(messageContent);

                var iconRect = new Rect(x, y + (DGUI.Properties.SingleLineHeight - iconSize) / 2, iconSize, iconSize);
                x += iconRect.width;
                x += DGUI.Properties.Space();
                var messageRect = new Rect(x, y + (DGUI.Properties.SingleLineHeight - messageContentSize.y) / 2, messageContentSize.x, messageContentSize.y);

                GUI.color = DGUI.Colors.BackgroundColor(colorName);

                DGUI.Icon.Draw(iconRect, Styles.GetStyle(Styles.StyleName.IconSoundy));
                DGUI.Label.Draw(messageRect, messageContent, Size.S);
            }
        }
Esempio n. 2
0
        private void DrawSoundy(Rect drawRect, SerializedProperty property, bool hasSound, bool hasMissingAudioClips, bool nameIsNoSound, SoundyAudioPlayer.Player player, ColorName backgroundColorName, ColorName textColorName)
        {
            Color initialColor = GUI.color;

            //LINE 1A
            SerializedProperty soundSource  = Properties.Get(PropertyName.SoundSource, property);
            SerializedProperty databaseName = Properties.Get(PropertyName.DatabaseName, property);
            SerializedProperty soundName    = Properties.Get(PropertyName.SoundName, property);

            float x = drawRect.x + DGUI.Properties.Space();
            float y = drawRect.y;

            var   outputLabelRect            = new Rect(x, y, OUTPUT_LABEL_WIDTH, TOP_ROW_HEIGHT);
            float databaseNameSoundNameWidth = (drawRect.width - OUTPUT_LABEL_WIDTH - DGUI.Properties.Space(5)) / 2;

            x += OUTPUT_LABEL_WIDTH + DGUI.Properties.Space();
            var databaseNameLabelRect = new Rect(x, y, databaseNameSoundNameWidth, TOP_ROW_HEIGHT);

            x += databaseNameSoundNameWidth + DGUI.Properties.Space();
            var soundNameLabelRect = new Rect(x, y, databaseNameSoundNameWidth, TOP_ROW_HEIGHT);

            DGUI.Label.Draw(outputLabelRect, UILabels.SoundSource, Size.S, textColorName);
            DGUI.Label.Draw(databaseNameLabelRect, UILabels.DatabaseName, Size.S, textColorName);
            DGUI.Label.Draw(soundNameLabelRect, UILabels.SoundName, Size.S, textColorName);

            //LINE 1B
            x  = drawRect.x + DGUI.Properties.Space();
            y += TOP_ROW_HEIGHT + DGUI.Properties.Space();
            var outputDropdownRect = new Rect(x, y, OUTPUT_LABEL_WIDTH, DGUI.Properties.SingleLineHeight);

            x += OUTPUT_LABEL_WIDTH + DGUI.Properties.Space();
            var databaseNameDropdownRect = new Rect(x, y, databaseNameSoundNameWidth, DGUI.Properties.SingleLineHeight);

            x += databaseNameSoundNameWidth + DGUI.Properties.Space();
            var soundNameDropdownRect = new Rect(x, y, databaseNameSoundNameWidth, DGUI.Properties.SingleLineHeight);

            SoundDatabase soundDatabase = SoundySettings.Database.GetSoundDatabase(databaseName.stringValue);

            if (soundDatabase == null)
            {
                databaseName.stringValue = SoundyManager.GENERAL;
                soundDatabase            = SoundySettings.Database.GetSoundDatabase(SoundyManager.GENERAL);
                if (soundDatabase == null)
                {
                    SoundySettings.Database.Initialize();
                }
                if (soundDatabase == null)
                {
                    return;
                }
            }

            int databaseIndex = SoundySettings.Database.DatabaseNames.IndexOf(databaseName.stringValue);

            int soundNameIndex;

            if (soundDatabase.SoundNames.Contains(soundName.stringValue))
            {
                soundNameIndex = soundDatabase.SoundNames.IndexOf(soundName.stringValue);
            }
            else
            {
                soundName.stringValue = SoundyManager.NO_SOUND;
                soundNameIndex        = soundDatabase.SoundNames.IndexOf(SoundyManager.NO_SOUND);
            }

            GUI.color = DGUI.Colors.PropertyColor(backgroundColorName);

            //DRAW - OUTPUT DROPDOWN
            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(outputDropdownRect, soundSource, GUIContent.none, true);
            if (EditorGUI.EndChangeCheck())
            {
                soundName.stringValue = "";
                if (player != null && player.IsPlaying)
                {
                    player.Stop();
                }
                DGUI.Properties.ResetKeyboardFocus();
            }

            //DRAW - DATABASE NAME DROPDOWN
            EditorGUI.BeginChangeCheck();
            databaseIndex = EditorGUI.Popup(databaseNameDropdownRect, databaseIndex, SoundySettings.Database.DatabaseNames.ToArray());
            if (EditorGUI.EndChangeCheck())
            {
                databaseName.stringValue = SoundySettings.Database.DatabaseNames[databaseIndex];
                DGUI.Properties.ResetKeyboardFocus();
                UpdateThisAudioDataPreviewReference(property);
                if (player != null && player.IsPlaying)
                {
                    player.Stop();
                }
            }

            if (hasMissingAudioClips && !nameIsNoSound)
            {
                GUI.color = DGUI.Colors.PropertyColor(ColorName.Red);
            }

            //DRAW - SOUND NAME NAME DROPDOWN
            EditorGUI.BeginChangeCheck();
            soundNameIndex = EditorGUI.Popup(soundNameDropdownRect, soundNameIndex, soundDatabase.SoundNames.ToArray());
            if (EditorGUI.EndChangeCheck())
            {
                soundName.stringValue = soundDatabase.SoundNames[soundNameIndex];
                DGUI.Properties.ResetKeyboardFocus();
                UpdateThisAudioDataPreviewReference(property);
                if (player != null && player.IsPlaying)
                {
                    player.Stop();
                }
            }

            GUI.color = initialColor;

            //LINE 2
            x  = drawRect.x + DGUI.Properties.Space();
            y += DGUI.Properties.SingleLineHeight + DGUI.Properties.Space();

            const float iconSize = 12f;

            var openSoundyButtonRect = new Rect(x, y, OUTPUT_LABEL_WIDTH, DGUI.Properties.SingleLineHeight);

            x += OUTPUT_LABEL_WIDTH;
            x += DGUI.Properties.Space(2);
            var outputAudioMixerGroupIconRect = new Rect(x, y + (DGUI.Properties.SingleLineHeight - iconSize) / 2, iconSize, iconSize);

            x += outputAudioMixerGroupIconRect.width;
            x += DGUI.Properties.Space();
            var outputAudioMixerGroupLabelRect = new Rect(x, y, drawRect.width - OUTPUT_LABEL_WIDTH - outputAudioMixerGroupIconRect.width - DGUI.Properties.Space(5), DGUI.Properties.SingleLineHeight);

            if (DGUI.Button.Draw(openSoundyButtonRect, DGUI.Properties.Labels.Soundy, Size.S, TextAlign.Center, hasMissingAudioClips && !nameIsNoSound ? ColorName.Red : DGUI.Colors.SoundyColorName, hasMissingAudioClips && !nameIsNoSound)) //draw Soundy sutton
            {
                DoozyWindow.Open(DoozyWindow.View.Soundy,
                                 () =>
                {
                    DoozyWindow.Instance.GetSoundDatabaseAnimBool(databaseName.stringValue).target = true;
                });
            }


            bool hasOutputAudioMixerGroup = player != null && player.OutputAudioMixerGroup != null;

            DGUI.Icon.Draw(outputAudioMixerGroupIconRect, Styles.GetStyle(Styles.StyleName.IconAudioMixerGroup), hasOutputAudioMixerGroup ? textColorName : DGUI.Colors.DisabledTextColorName);               //draw audio mixer group icon
            DGUI.Label.Draw(outputAudioMixerGroupLabelRect, player != null ? player.OutputAudioMixerGroupName : "---", Size.S, hasOutputAudioMixerGroup ? textColorName : DGUI.Colors.DisabledTextColorName); //draw audio mixer group name
            GUI.color = initialColor;

            //LINE 3
            x  = drawRect.x + DGUI.Properties.Space();
            y += DGUI.Properties.SingleLineHeight + DGUI.Properties.Space();

            DrawPlayer(drawRect, x, y, hasSound, player, textColorName);

            GUI.color = initialColor;
        }
Esempio n. 3
0
        private void DrawAudioClip(Rect drawRect, SerializedProperty property, bool hasSound, SoundyAudioPlayer.Player player, ColorName backgroundColorName, ColorName textColorName)
        {
            Color initialColor = GUI.color;

            SerializedProperty soundSource           = Properties.Get(PropertyName.SoundSource, property);
            SerializedProperty audioClip             = Properties.Get(PropertyName.AudioClip, property);
            SerializedProperty outputAudioMixerGroup = Properties.Get(PropertyName.OutputAudioMixerGroup, property);

            //LINE 1A
            float x = drawRect.x + DGUI.Properties.Space();
            float y = drawRect.y;

            var   outputLabelRect     = new Rect(x, y, OUTPUT_LABEL_WIDTH, TOP_ROW_HEIGHT);
            float audioClipLabelWidth = drawRect.width - OUTPUT_LABEL_WIDTH - DGUI.Properties.Space(4);

            x += OUTPUT_LABEL_WIDTH + DGUI.Properties.Space();
            var audioClipLabelRect = new Rect(x, y, audioClipLabelWidth, TOP_ROW_HEIGHT);


            DGUI.Label.Draw(outputLabelRect, UILabels.SoundSource, Size.S, textColorName);
            DGUI.Label.Draw(audioClipLabelRect, UILabels.AudioClip, Size.S, textColorName);

            //LINE 1B
            x  = drawRect.x + DGUI.Properties.Space();
            y += TOP_ROW_HEIGHT + DGUI.Properties.Space();
            var outputDropdownRect = new Rect(x, y, OUTPUT_LABEL_WIDTH, DGUI.Properties.SingleLineHeight);

            x += OUTPUT_LABEL_WIDTH + DGUI.Properties.Space();
            var audioClipRect = new Rect(x, y, audioClipLabelWidth, DGUI.Properties.SingleLineHeight);

            GUI.color = DGUI.Colors.PropertyColor(backgroundColorName);

            //DRAW - OUTPUT DROPDOWN
            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(outputDropdownRect, soundSource, GUIContent.none, true);
            if (EditorGUI.EndChangeCheck())
            {
                Properties.Get(PropertyName.SoundName, property).stringValue = "";
                if (player != null && player.IsPlaying)
                {
                    player.Stop();
                }
                DGUI.Properties.ResetKeyboardFocus();
            }

            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(audioClipRect, audioClip, GUIContent.none, true);
            if (EditorGUI.EndChangeCheck())
            {
                if (player != null && player.IsPlaying)
                {
                    player.Stop();
                }
                DGUI.Properties.ResetKeyboardFocus();
            }

            GUI.color = initialColor;

            //LINE 2
            x  = drawRect.x + DGUI.Properties.Space();
            y += DGUI.Properties.SingleLineHeight + DGUI.Properties.Space(2);

            var     outputAudioMixerGroupContent     = new GUIContent(UILabels.OutputAudioMixerGroup);
            Vector2 outputAudioMixerGroupContentSize = DGUI.Label.Style(Size.S).CalcSize(outputAudioMixerGroupContent);

            const float iconSize = 12f;

            var outputAudioMixerGroupIconRect = new Rect(x, y + (DGUI.Properties.SingleLineHeight - iconSize) / 2, iconSize, iconSize);

            x += iconSize;
            x += DGUI.Properties.Space();
            var outputAudioMixerGroupLabelRect = new Rect(x, y + (DGUI.Properties.SingleLineHeight - outputAudioMixerGroupContentSize.y) / 2, outputAudioMixerGroupContentSize.x, outputAudioMixerGroupContentSize.y);

            x += outputAudioMixerGroupContentSize.x;
            x += DGUI.Properties.Space(2);
            var outputAudioMixerGroupRect = new Rect(x, y, drawRect.width - DGUI.Properties.Space(6) - outputAudioMixerGroupIconRect.width - outputAudioMixerGroupLabelRect.width, DGUI.Properties.SingleLineHeight);

            bool hasOutputAudioMixerGroup = outputAudioMixerGroup.objectReferenceValue != null;

            DGUI.Icon.Draw(outputAudioMixerGroupIconRect, Styles.GetStyle(Styles.StyleName.IconAudioMixerGroup), hasOutputAudioMixerGroup ? textColorName : DGUI.Colors.DisabledTextColorName);
            DGUI.Label.Draw(outputAudioMixerGroupLabelRect, outputAudioMixerGroupContent, Size.S, hasOutputAudioMixerGroup ? textColorName : DGUI.Colors.DisabledTextColorName);

            GUI.color = initialColor;

            EditorGUI.BeginChangeCheck();
            DGUI.Property.Draw(outputAudioMixerGroupRect, outputAudioMixerGroup, hasOutputAudioMixerGroup ? backgroundColorName : DGUI.Colors.DisabledBackgroundColorName);
            if (EditorGUI.EndChangeCheck())
            {
                if (player != null && player.IsPlaying)
                {
                    player.Stop();
                }
                DGUI.Properties.ResetKeyboardFocus();
            }

            GUI.color = initialColor;

            //LINE 3
            x  = drawRect.x + DGUI.Properties.Space();
            y += DGUI.Properties.SingleLineHeight + DGUI.Properties.Space();

            DrawPlayer(drawRect, x, y, hasSound, player, textColorName);

            GUI.color = initialColor;
        }
Esempio n. 4
0
        private void Draw(Rect position, SerializedProperty property)
        {
            Color initialColor = GUI.color; //save the GUI color

            SoundyAudioPlayer.Player player = null;
            bool     nameIsNoSound          = false;
            bool     hasSound             = false;
            bool     hasMissingAudioClips = false;
            GUIStyle icon;

            var soundSource = (SoundSource)Properties.Get(PropertyName.SoundSource, property).intValue;

            switch (soundSource)
            {
            case SoundSource.Soundy:
                NumberOfLines[property.propertyPath] = 4;
                player = SoundyAudioPlayer.GetPlayer(GetAudioData(Properties.Get(PropertyName.DatabaseName, property).stringValue, Properties.Get(PropertyName.SoundName, property).stringValue),
                                                     GetAudioMixerGroup(Properties.Get(PropertyName.DatabaseName, property).stringValue));
                if (player != null && player.SoundGroupData != null)
                {
                    nameIsNoSound        = Properties.Get(PropertyName.SoundName, property).stringValue.Equals(SoundyManager.NO_SOUND);
                    hasSound             = player.SoundGroupData.HasSound;
                    hasMissingAudioClips = player.SoundGroupData.HasMissingAudioClips;
                }

                icon = Styles.GetStyle(Styles.StyleName.IconSoundy);
                break;

            case SoundSource.AudioClip:
                NumberOfLines[property.propertyPath] = 4;
                player = SoundyAudioPlayer.GetPlayer((AudioClip)Properties.Get(PropertyName.AudioClip, property).objectReferenceValue,
                                                     (AudioMixerGroup)Properties.Get(PropertyName.OutputAudioMixerGroup, property).objectReferenceValue);
                hasSound = player != null && player.AudioClip != null;
                icon     = Styles.GetStyle(Styles.StyleName.IconSound);
                break;

            case SoundSource.MasterAudio:
                NumberOfLines[property.propertyPath] = 2;
                hasSound = !string.IsNullOrEmpty(Properties.Get(PropertyName.SoundName, property).stringValue);
                icon     = Styles.GetStyle(DoozySettings.Instance.UseMasterAudio ? Styles.StyleName.IconMasterAudio : Styles.StyleName.IconError);
                break;

            default: throw new ArgumentOutOfRangeException();
            }

            ColorName backgroundColorName = hasSound ? DrawerColorName : DGUI.Colors.DisabledBackgroundColorName;
            ColorName textColorName       = hasSound ? DrawerColorName : DGUI.Colors.DisabledTextColorName;

            Rect drawRect = GetDrawRectAndDrawBackground(position, NumberOfLines[property.propertyPath], backgroundColorName); //calculate draw rect and draw background

            drawRect    = InsertDrawerIcon(drawRect, property, soundSource != SoundSource.MasterAudio ? backgroundColorName : DoozySettings.Instance.UseMasterAudio ? ColorName.White : ColorName.Red, icon);
            drawRect.y += DGUI.Properties.Space();

            switch (soundSource)
            {
            case SoundSource.Soundy:
                DrawSoundy(drawRect, property, hasSound, hasMissingAudioClips, nameIsNoSound, player, backgroundColorName, textColorName);
                break;

            case SoundSource.AudioClip:
                DrawAudioClip(drawRect, property, hasSound, player, backgroundColorName, textColorName);
                break;

            case SoundSource.MasterAudio:
                DrawMasterAudio(drawRect, property, backgroundColorName, textColorName);
                break;
            }

            GUI.color = initialColor; //restore the GUI color
        }