snozbot / fungus

An easy to use Unity 3D library for creating illustrated Interactive Fiction games and more.
MIT License
1.6k stars 291 forks source link

Musicmanager.cs is missing code to support volume adjustments. #958

Open ianicmathieu opened 3 years ago

ianicmathieu commented 3 years ago

Fungus users would greatly benefit having a complete audio volume control for Fungus and we are not very far.

In the last months, with the help of Petter, we've implemented the AudioMusic Slider, AudioSoundEffect slider a AudioAmbiance slider to be complete.

The musicmanager is missing these entries for separate volume control which is part of the solution. The other part is including 3 Set Audio volume for Music, Ambience and Soundeffects

public virtual void SetAudioVolumeMusic(float volume, float duration, System.Action onComplete) { if (Mathf.Approximately(duration, 0f)) { if (onComplete != null) { onComplete(); } audioSourceMusic.volume = volume;

            return;
        }

        LeanTween.value(gameObject,
            audioSourceMusic.volume,
            volume,
            duration).setOnUpdate((v) => {
                audioSourceMusic.volume = v;

            }).setOnComplete(() => {
                if (onComplete != null)
                {
                    onComplete();
                }
            });
    }
    public virtual void SetAudioVolumeFX(float volume, float duration, System.Action onComplete)
    {
        if (Mathf.Approximately(duration, 0f))
        {
            if (onComplete != null)
            {
                onComplete();
            }

            audioSourceSoundEffect.volume = volume;
            return;
        }

        LeanTween.value(gameObject,
            audioSourceSoundEffect.volume,
            volume,
            duration).setOnUpdate((v) => {

                audioSourceSoundEffect.volume = v;
            }).setOnComplete(() => {
                if (onComplete != null)
                {
                    onComplete();
                }
            });
    }
    public virtual void SetAudioVolumeAmbiance(float volume, float duration, System.Action onComplete)
    {
        if (Mathf.Approximately(duration, 0f))
        {
            if (onComplete != null)
            {
                onComplete();
            }
            audioSourceAmbiance.volume = volume;

            return;
        }

        LeanTween.value(gameObject,
            audioSourceAmbiance.volume,
            volume,
            duration).setOnUpdate((v) => {
                audioSourceAmbiance.volume = v;

            }).setOnComplete(() => {
                if (onComplete != null)
                {
                    onComplete();
                }
            });
    }