Simple-Unity-Audio-Manager icon indicating copy to clipboard operation
Simple-Unity-Audio-Manager copied to clipboard

[Ask] Mixer on outside JSAM Audio Source

Open StinkySteak opened this issue 1 year ago • 2 comments

JSAM Version: 3.0.0 preview 6 Unity: 2021.3.21f1

How do we make sure the mixer works for a audio source not managed by JSAM?

StinkySteak avatar May 27 '24 12:05 StinkySteak

It seems the mixer doesn't really used or functioned?

For my case I currently call Start/Awake/OnEnable, then call my source.volume = AudioManager.SoundVolume

StinkySteak avatar May 28 '24 10:05 StinkySteak

There is currently no easy way to make JSAM's Audio Manager manage your own Audio Source. I'll be working on adding a solution for this in the next update.

I apologize for the long wait, but if if you still need help on this issue, what you can do is create a script that hooks onto the AudioManager's volume change events and changes an AudioSource's volume level automatically. Something like the below.

public class ManagedSource : MonoBehaviour
{
    public float relativeVolume;
    public AudioSource source;

    private void Start()
    {
        AudioManager.OnSoundVolumeChanged += UpdateVolume;
    }

    private void OnDestroy()
    {
        AudioManager.OnSoundVolumeChanged -= UpdateVolume;
    }

    void UpdateVolume(float v)
    {
        source.volume = relativeVolume * v * AudioManager.MasterVolume;
    }
}

jackyyang09 avatar Jul 12 '24 22:07 jackyyang09