Example #1
0
        void DrawButtonSection()
        {
            if (targets.Length > 1)
            {
                return;
            }

            SerializedProperty clipsProperty = serializedObject.FindProperty("_audioClips");

            if (Event.current.commandName == "ObjectSelectorClosed" && _pickedObjectReady)
            {
                _pickedObjectReady = false;
                if (EditorGUIUtility.GetObjectPickerObject() != null)
                {
                    if (clipsProperty.arraySize == 0 || clipsProperty.GetArrayElementAtIndex(clipsProperty.arraySize - 1).objectReferenceValue != null)
                    {
                        clipsProperty.arraySize++;
                    }

                    clipsProperty.GetArrayElementAtIndex(clipsProperty.arraySize - 1).objectReferenceValue = EditorGUIUtility.GetObjectPickerObject();
                    serializedObject.ApplyModifiedProperties();
                }
            }

            GUILayout.BeginHorizontal();

            if (clipsProperty != null)
            {
                if (GUILayout.Button("Add Clip", GUILayout.MaxWidth(80)))
                {
                    UnityEngine.Object defaultClip = null;

                    if (clipsProperty.arraySize > 0)
                    {
                        defaultClip = clipsProperty.GetArrayElementAtIndex(clipsProperty.arraySize - 1).objectReferenceValue;
                    }

                    _pickedObjectReady = true;
                    EditorGUIUtility.ShowObjectPicker <AudioClip>(defaultClip, false, "", -1);
                }

                if (GUILayout.Button("Clear Clips", GUILayout.MaxWidth(80)))
                {
                    clipsProperty.arraySize = 0;
                    serializedObject.ApplyModifiedProperties();
                }
            }

            if (_bank is BlendSoundBank)
            {
                EditorGUIUtility.labelWidth = 45f;
                _blendParameter             = EditorGUILayout.Slider(new GUIContent("Blend"), _blendParameter, 0, 1);
            }
            else if (_bank is SequenceSoundBank)
            {
                SequenceSoundInstance sequence = null;
                if (_lastInstance != null)
                {
                    sequence = _lastInstance as SequenceSoundInstance;
                }

                if (sequence != null && sequence.HasPreviousSection)
                {
                    if (GUILayout.Button("<<", GUILayout.MaxWidth(50f)))
                    {
                        sequence.PlayPreviousSection();
                    }
                }
                else
                {
                    EditorGUI.BeginDisabledGroup(true);
                    GUILayout.Button("<<", GUILayout.MaxWidth(50f));
                    EditorGUI.EndDisabledGroup();
                }

                if (sequence != null && sequence.HasNextSection)
                {
                    if (GUILayout.Button(">>", GUILayout.MaxWidth(50f)))
                    {
                        sequence.PlayNextSection();
                    }
                }
                else
                {
                    EditorGUI.BeginDisabledGroup(true);
                    GUILayout.Button(">>", GUILayout.MaxWidth(50f));
                    EditorGUI.EndDisabledGroup();
                }

                GUILayout.FlexibleSpace();
            }
            else
            {
                GUILayout.FlexibleSpace();
            }

            if (GUILayout.Button("PLAY", GUILayout.MaxWidth(80f)))
            {
                if (_soundPool == null)
                {
                    _soundPool = new EditorSoundPool();
                    Selection.selectionChanged += _soundPool.Clear;
                }
                else
                {
                    _soundPool.Clear();
                }

                _lastInstance = _bank.TestInEditor(_soundPool);
            }

            if (GUILayout.Button("STOP", GUILayout.MaxWidth(80f)))
            {
                if (_lastInstance != null)
                {
                    _lastInstance.StopAndDestroy();
                }
            }

            BlendSoundInstance blend = _lastInstance as BlendSoundInstance;

            if (blend != null)
            {
                blend.SetBlendParameter(_blendParameter);
            }

            GUILayout.EndHorizontal();
        }
Example #2
0
        void OnGUI()
        {
            SoundBoardWindow window = (SoundBoardWindow)GetWindow(typeof(SoundBoardWindow), false, "Sound Board");

            window.minSize = new Vector2(412f, 80f);

            if (_soundPool == null)
            {
                _soundPool = new EditorSoundPool();
            }

            if (_buttonStyle == null)
            {
                _buttonStyle        = new GUIStyle(GUI.skin.GetStyle("Button"));
                _buttonStyle.margin = new RectOffset(4, 4, 1, 0);
            }



            GUILayout.Space(10f);
            GUILayout.BeginHorizontal();

            GUILayout.Space(20f);
            GUILayout.Label("Sound Bank", "BoldLabel", GUILayout.MinWidth(200f), GUILayout.MaxWidth(300f));

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("PLAY ALL", GUILayout.MinWidth(80f), GUILayout.MaxWidth(100f)))
            {
                for (int i = 0; i < _soundInstances.Count; i++)
                {
                    StopSound(i);
                    PlaySound(i);
                }
            }
            if (GUILayout.Button("STOP", GUILayout.MaxWidth(80f)))
            {
                for (int i = 0; i < _soundInstances.Count; i++)
                {
                    StopSound(i);
                }
            }
            if (GUILayout.Button("X", GUILayout.MaxWidth(25f)))
            {
                _soundPool.Clear();
                _soundInstances.Clear();
                _soundBanks.Clear();
            }

            GUILayout.Space(15f);
            GUILayout.EndHorizontal();

            GUILayout.BeginVertical("GroupBox");



            for (int i = 0; i < _soundBanks.Count; i++)
            {
                DrawRow(i);
            }

            EditorGUILayout.BeginHorizontal();

            Object newBank = EditorGUILayout.ObjectField("", null, typeof(SoundBank), false, GUILayout.Width(_newBankWidth));

            if (newBank != null)
            {
                _soundBanks.Add((SoundBank)newBank);
                _soundInstances.Add(null);
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }