Exemplo n.º 1
0
    private void Awake()
    {
        if (instance)
        {
            Debug.LogError("EZ Sound Manager already exists!");
            Destroy(gameObject);
            return;
        }

        instance = this;
    }
Exemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        EZSoundManager ezSoundManager = (EZSoundManager)target;

        if (!ezSoundManager)
        {
            return;
        }

        Undo.RecordObject(ezSoundManager, "");

        EditorGUILayout.Space();
        DrawSoundList(ezSoundManager);
        EditorGUILayout.Space();
        DrawMusicList(ezSoundManager);

        EditorGUILayout.Space();

        ezSoundManager.soundPoolSize = EditorGUILayout.IntField("Sound Pool Size", ezSoundManager.soundPoolSize);
        ezSoundManager.musicPoolSize = EditorGUILayout.IntField("Music Pool Size", ezSoundManager.musicPoolSize);
    }
Exemplo n.º 3
0
    private void DrawSoundList(EZSoundManager ezSoundManager)
    {
        GUILayout.Label("Sound List", new GUIStyle()
        {
            fontSize  = 25,
            fontStyle = FontStyle.Bold,
        });

        EditorGUILayout.BeginVertical("Box", GUILayout.Width(420));

        EditorGUILayout.BeginHorizontal();

        GUILayout.Space(20);
        GUILayout.Label("Edit", GUILayout.Width(40));
        GUILayout.Label("Name", GUILayout.Width(120));
        GUILayout.Label("Audio Clips", GUILayout.Width(250));

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        foreach (EZSoundManager.Sound sound in ezSoundManager.soundList)
        {
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("X", GUILayout.Width(20)))
            {
                ezSoundManager.soundList.Remove(sound);
                break;
            }

            if (GUILayout.Button("Edit", GUILayout.Width(40)))
            {
                _previewer.Stop();
                _editSound = _editSound == sound ? null : sound;
            }

            sound.name = EditorGUILayout.TextField(sound.name, GUILayout.Width(120));

            if (_editSound == sound || sound.clips.Count == 0)
            {
                _editMusic = null;

                EditorGUILayout.BeginVertical();

                if (_editSound != null)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Volume", GUILayout.Width(50));
                    EditorGUILayout.MinMaxSlider(ref _editSound.minVolume, ref _editSound.maxVolume, 0.0f, 1.0f);
                    _previewer.volume = sound.RandomVolume;
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Pitch", GUILayout.Width(50));
                    EditorGUILayout.MinMaxSlider(ref _editSound.minPitch, ref _editSound.maxPitch, 1.0f, 3.0f);
                    _previewer.pitch = sound.RandomPitch;
                    EditorGUILayout.EndHorizontal();
                }

                for (int i = 0; i < sound.clips.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    sound.clips[i] = (AudioClip)EditorGUILayout.ObjectField(sound.clips[i], typeof(AudioClip), false, GUILayout.Width(250));

                    if (GUILayout.Button("Play"))
                    {
                        _previewer.clip = sound.clips[i];
                        _previewer.Play();
                    }
                    if (GUILayout.Button("Stop"))
                    {
                        _previewer.Stop();
                    }

                    EditorGUILayout.EndHorizontal();

                    if (sound.clips[i] != null)
                    {
                        continue;
                    }

                    sound.clips.RemoveAt(i);
                    break;
                }

                AudioClip newClip = (AudioClip)EditorGUILayout.ObjectField(null, typeof(AudioClip), false, GUILayout.Width(150));
                if (newClip)
                {
                    sound.clips.Add(newClip);
                }

                EditorGUILayout.Space(10);

                EditorGUILayout.EndVertical();
            }
            else
            {
                GUILayout.Label($"{sound.clips.Count.ToString()} audio clip(s)", EditorStyles.boldLabel);

                if (GUILayout.Button("Play"))
                {
                    _previewer.clip   = sound.GetRandomClip();
                    _previewer.volume = sound.RandomVolume;
                    _previewer.pitch  = sound.RandomPitch;
                    _previewer.Play();
                }
                if (GUILayout.Button("Stop"))
                {
                    _previewer.Stop();
                }
            }

            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Add", GUILayout.Width(60)))
        {
            ezSoundManager.soundList.Add(new EZSoundManager.Sound());
            _editSound = ezSoundManager.soundList[ezSoundManager.soundList.Count - 1];
        }

        if (GUILayout.Button("Sort", GUILayout.Width(60)))
        {
            ezSoundManager.soundList.Sort((a, b) => string.Compare(a.name, b.name));
            foreach (EZSoundManager.Sound sound in ezSoundManager.soundList)
            {
                sound.clips.Sort((a, b) => string.Compare(a.ToString(), b.ToString()));
            }
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();
    }
Exemplo n.º 4
0
    private void DrawMusicList(EZSoundManager ezSoundManager)
    {
        GUILayout.Label("Music List", new GUIStyle()
        {
            fontSize  = 25,
            fontStyle = FontStyle.Bold,
        });

        EditorGUILayout.BeginVertical("Box", GUILayout.Width(420));

        EditorGUILayout.BeginHorizontal();

        GUILayout.Space(20);
        GUILayout.Label("Edit", GUILayout.Width(40));
        GUILayout.Label("Name", GUILayout.Width(120));
        GUILayout.Label("Audio Clips", GUILayout.Width(250));

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        foreach (EZSoundManager.Music music in ezSoundManager.musicList)
        {
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("X", GUILayout.Width(20)))
            {
                ezSoundManager.musicList.Remove(music);
                break;
            }

            if (GUILayout.Button("Edit", GUILayout.Width(40)))
            {
                _previewer.Stop();
                _editMusic = _editMusic == music ? null : music;
            }

            music.name = EditorGUILayout.TextField(music.name, GUILayout.Width(120));

            if (_editMusic == music || !music.clip)
            {
                EditorGUILayout.BeginVertical();

                if (_editMusic != null)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Volume", GUILayout.Width(50));
                    _editMusic.volume = EditorGUILayout.Slider(_editMusic.volume, 0.0f, 1.0f);
                    _previewer.volume = music.volume;
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Loop", GUILayout.Width(50));
                    _editMusic.loop  = EditorGUILayout.Toggle(_editMusic.loop);
                    _previewer.pitch = 1.0f;
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.BeginHorizontal();
                music.clip = (AudioClip)EditorGUILayout.ObjectField(music.clip, typeof(AudioClip), false,
                                                                    GUILayout.Width(250));

                if (GUILayout.Button("Play"))
                {
                    _previewer.clip = music.clip;
                    _previewer.Play();
                }

                if (GUILayout.Button("Stop"))
                {
                    _previewer.Stop();
                }

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space(10);

                EditorGUILayout.EndVertical();
            }
            else
            {
                GUILayout.Label($"{music.clip.name}", EditorStyles.boldLabel);

                if (GUILayout.Button("Play"))
                {
                    _previewer.clip   = music.clip;
                    _previewer.volume = music.volume;
                    _previewer.pitch  = 1.0f;
                    _previewer.Play();
                }
                if (GUILayout.Button("Stop"))
                {
                    _previewer.Stop();
                }
            }

            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Add", GUILayout.Width(60)))
        {
            ezSoundManager.musicList.Add(new EZSoundManager.Music());
            _editMusic = ezSoundManager.musicList[ezSoundManager.musicList.Count - 1];
        }

        if (GUILayout.Button("Sort", GUILayout.Width(60)))
        {
            ezSoundManager.musicList.Sort((a, b) => string.Compare(a.name, b.name));
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();
    }