Struct AudioDistanceAttenuation
An AudioDistanceAttenuation component adjusts an AudioSource's volume.
Namespace: Unity.Tiny.Audio
Syntax
public struct AudioDistanceAttenuation : IComponentData
Remarks
The AudioSystem automatically adjusts the associated AudioSource's volume
based on the AudioSource's distance from the AudioListener and the properties
in this component. When an AudioSource is less than minDistance away from the
AudioListener, the volume is not changed. When an AudioSource is further than
maxDistance away from the AudioListener, the volume is zero. The volume parameter
is set internally by the AudioSystem and is the last calculated distance-attenuation
volume.
var eSource = mgr.CreateEntity();
AudioSource source = new AudioSource();
source.clip = eClip;
mgr.AddComponentData(eSource, source);
Audio3dPanning panning = new Audio3dPanning();
mgr.AddComponentData(eSource, panning);
AudioDistanceAttenuation distanceAttenuation = new AudioDistanceAttenuation();
distanceAttenuation.rolloffMode = AudioRolloffMode.Logarithmic;
distanceAttenuation.minDistance = 3.0f;
distanceAttenuation.maxDistance = 50.0f;
mgr.AddComponentData(eSource, distanceAttenuation);
mgr.AddComponent(eSource, typeof(AudioSourceStart));
Fields
maxDistance
Declaration
public float maxDistance
Field Value
Type | Description |
---|---|
Single |
minDistance
Declaration
public float minDistance
Field Value
Type | Description |
---|---|
Single |
rolloffMode
Declaration
public AudioRolloffMode rolloffMode
Field Value
Type | Description |
---|---|
AudioRolloffMode |
Properties
volume
Declaration
public float volume { get; }
Property Value
Type | Description |
---|---|
Single |