Class ChannelAudioSource
Plays an UnityEngine.AudioSource through one of the player's volume channels.
[AddComponentMenu("FishMMO/Audio/Channel Audio Source")]
[RequireComponent(typeof(AudioSource))]
public sealed class ChannelAudioSource : MonoBehaviour
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourChannelAudioSource
- Inherited Members
-
MonoBehaviour.IsInvoking()MonoBehaviour.CancelInvoke()MonoBehaviour.StopCoroutine(Coroutine)MonoBehaviour.StopAllCoroutines()MonoBehaviour.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.GetComponent<T>()Component.TryGetComponent<T>(out T)Component.GetComponentInChildren<T>()Component.GetComponentsInChildren<T>()Component.GetComponentInParent<T>()Component.GetComponentsInParent<T>()Component.GetComponents<T>()Component.GetComponentIndex()Component.CompareTag(TagHandle)Component.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.GetEntityId()Object.GetInstanceID()Object.GetHashCode()Object.InstantiateAsync<T>(T)Object.InstantiateAsync<T>(T, Transform)Object.InstantiateAsync<T>(T, Vector3, Quaternion)Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion, Transform)Object.Instantiate(Object)Object.Instantiate(Object, Scene)Object.Instantiate<T>(T, InstantiateParameters)Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)Object.Instantiate(Object, Transform)Object.Instantiate<T>(T)Object.Instantiate<T>(T, Vector3, Quaternion)Object.Instantiate<T>(T, Vector3, Quaternion, Transform)Object.Instantiate<T>(T, Transform)Object.Destroy(Object)Object.DestroyImmediate(Object)Object.DontDestroyOnLoad(Object)Object.DestroyObject(Object)Object.FindObjectsOfType<T>()Object.FindObjectsByType<T>(FindObjectsSortMode)Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)Object.FindObjectOfType<T>()Object.FindFirstObjectByType<T>()Object.FindAnyObjectByType<T>()Object.FindFirstObjectByType<T>(FindObjectsInactive)Object.FindAnyObjectByType<T>(FindObjectsInactive)Object.FindObjectsByType<T>()Object.FindObjectsByType<T>(FindObjectsInactive)Object.ToString()Object.nameObject.hideFlags
Remarks
The channel model already existed and only Master was ever applied, through UnityEngine.AudioListener.volume. That covers every sound at once, which is why it worked without anything like this component, and also why nothing finer than "all of it" could be offered. This is the missing piece: it scales one source by its own channel so a player can turn music down without turning combat down with it.
Deliberately not an AudioMixer. A mixer is the usual answer and is a better one once
there is an audio team, but its groups and exposed parameters live in a binary asset that
can only be authored by hand in the editor, and every source has to be pointed at a group
there as well. This keeps the routing in code, where it can be tested and where adding a
sound means adding a component rather than editing a shared asset.
Properties
AuthoredVolume
The volume this sound was authored at, ignoring the player's channel level.
public float AuthoredVolume { get; set; }
Property Value
Remarks
Assign through here rather than to AudioSource.volume when code wants to change
how loud a sound is in the mix -- fading a track in, quietening a source with distance.
Writing the source directly works until the player next moves a slider, at which point
the value is overwritten by this component and the change is silently lost.
Channel
The channel this source plays on.
public AudioChannel Channel { get; }
Property Value
Methods
Apply()
Writes the authored volume, scaled by the player's level for this channel.
public void Apply()
ChannelScale(AudioChannel)
The multiplier a channel contributes to a source.
public static float ChannelScale(AudioChannel channel)
Parameters
channelAudioChannelThe channel to scale by.
Returns
Remarks
One for Master, which is not a per-source channel: it is already on the listener, and a source tagged Master would otherwise be scaled by it twice. Returning one rather than refusing the assignment keeps a mis-tagged source merely un-scaled instead of silent, which is the better way to be wrong.
SetChannel(AudioChannel)
Points this source at a different channel.
public void SetChannel(AudioChannel value)
Parameters
valueAudioChannelThe channel to follow.