[FEATURE] Extend AudioManager to be able to provide a default AudioMixerGroup

echtnice

Member
Hi!

In my project I use different AudioMixerGroups to control the volume of different sound types. It would be helpful if AudioManager can ensure that
a default AudioMixerGroup is set, if not otherwise specified in the AudioSource like I did in the patch below. Would you be interested in merging this upstream? Thanks.

Code:
--- C:/AudioManager.cs Thu Jul  8 18:32:39 2021
+++ C:/Opsive/UltimateCharacterController/Scripts/Audio/AudioManager.cs Thu Jul  8 18:32:39 2021
@@ -31,6 +31,10 @@
         }
         private static bool s_Initialized;
 
+        //GUNFU:HACK 15.12.2020 - support audiomixergroup
+        [SerializeField] protected AudioMixerGroup m_Output;
+        //GUNFU:HACK 15.12.2020 - support audiomixergroup
+
         /// <summary>
         /// The AudioSourcesIndex class allows for an AudioSource to be selected based upon its play state. If all AudioSources are being 
         /// played then a new AudioSource will be added.
@@ -137,6 +141,10 @@
                     CopyAudioProperties(copyFromAudioSource, audioSource);
                 }
                 audioSource.spatialBlend = m_AudioManagerGameObject ? 0 : 1;
+                //GUNFU:HACK: 26.01.2021 - audio sound assign SFX when null
+                if (audioSource.outputAudioMixerGroup == null) {
+                    audioSource.outputAudioMixerGroup = Instance.m_Output;
+                }
 
                 return audioSource;
             }
@@ -156,6 +164,9 @@
                     addGameObject.transform.parent = m_GameObject.transform;
                 }
                 var newAudioSource = addGameObject.AddComponent<AudioSource>();
+                //GUNFU:HACK 15.12.2020 - support audiomixergroup
+                newAudioSource.outputAudioMixerGroup = Instance.m_Output;
+                //GUNFU:HACK 15.12.2020 - support audiomixergroup
                 newAudioSource.playOnAwake = false;
                 newAudioSource.volume = volume;
                 if (!m_AudioManagerGameObject) {
 

Attachments

  • AudioManager.patch.txt
    1.7 KB · Views: 0
Top