Class AudioSource
Represents a source for emitting audio. Audio can be played spatially (gun shot), or normally (music). Each audio source must have an AudioClip to play - back, and it can also have a position in the case of spatial (3D) audio.
Namespace: FlaxEngine
Assembly: FlaxEngine.CSharp.dll
Syntax
[ActorContextMenu("New/Audio/Audio Source")]
[ActorToolbox("Other")]
[Unmanaged]
public class AudioSource : Actor, ISerializable
Remarks
Whether or not an audio source is spatial is controlled by the assigned AudioClip.The volume and the pitch of a spatial audio source is controlled by its position and the AudioListener's position/direction/velocity.
Constructors
AudioSource()
Properties
AllowSpatialization
If checked, source can play spatial 3d audio (when audio clip supports it), otherwise will always play as 2d sound.
Declaration
[EditorOrder(80)]
[EditorDisplay("Audio Source", null)]
[Unmanaged]
public bool AllowSpatialization { get; set; }
Property Value
System.Boolean
|
Attenuation
Gets or sets the attenuation that controls how quickly does audio volume drop off as the listener moves further from the source.
Declaration
[EditorOrder(70)]
[Limit(0F, 3.40282347E+38F, 0.1F)]
[EditorDisplay("Audio Source", null)]
[Unmanaged]
public float Attenuation { get; set; }
Property Value
System.Single
|
Clip
The audio clip asset used as a source of the sound.
Declaration
[EditorOrder(10)]
[EditorDisplay("Audio Source", null)]
[Unmanaged]
public AudioClip Clip { get; set; }
Property Value
AudioClip
|
DopplerFactor
Gets or sets the doppler effect factor. Scale for source velocity. Default is 1.
Declaration
[EditorOrder(75)]
[Limit(0F, 3.40282347E+38F, 0.1F)]
[EditorDisplay("Audio Source", null)]
[Unmanaged]
public float DopplerFactor { get; set; }
Property Value
System.Single
|
Is3D
Returns true if the sound source is three-dimensional (volume and pitch varies based on listener distance and velocity).
Declaration
[Unmanaged]
public bool Is3D { get; }
Property Value
System.Boolean
|
IsActuallyPlaying
Determines whether this audio source started playing audio via audio backend. After audio play it may wait for audio clip data to be loaded or streamed.
Declaration
[Unmanaged]
public bool IsActuallyPlaying { get; }
Property Value
System.Boolean
|
IsActuallyPlayingSth
Determines whether this audio source started playing audio via audio backend. After audio play it may wait for audio clip data to be loaded or streamed. [Deprecated in v1.9]
Declaration
[Unmanaged]
public bool IsActuallyPlayingSth { get; }
Property Value
System.Boolean
|
IsLooping
Determines whether the audio clip should loop when it finishes playing.
Declaration
[EditorOrder(40)]
[EditorDisplay("Audio Source", null)]
[Unmanaged]
public bool IsLooping { get; set; }
Property Value
System.Boolean
|
MinDistance
Gets or sets the minimum distance at which audio attenuation starts. When the listener is closer to the source than this value, audio is heard at full volume. Once farther away the audio starts attenuating.
Declaration
[EditorOrder(60)]
[Limit(0F, 3.40282347E+38F, 0.1F)]
[EditorDisplay("Audio Source", null)]
[Unmanaged]
public float MinDistance { get; set; }
Property Value
System.Single
|
Pan
Gets or sets the stereo pan of the played audio (-1 is left speaker, 1 is right speaker, 0 is balanced). The default is 1. Used by non-spatial audio only.
Declaration
[EditorOrder(30)]
[Limit(-1F, 1F, 1F)]
[EditorDisplay("Audio Source", null)]
[Unmanaged]
public float Pan { get; set; }
Property Value
System.Single
|
Pitch
Gets or sets the pitch of the played audio. The default is 1.
Declaration
[EditorOrder(30)]
[Limit(0.5F, 2F, 0.01F)]
[EditorDisplay("Audio Source", null)]
[Unmanaged]
public float Pitch { get; set; }
Property Value
System.Single
|
PlayOnStart
Determines whether the audio clip should autoplay on level start.
Declaration
[EditorOrder(50)]
[EditorDisplay("Audio Source", "Play On Start")]
[Unmanaged]
public bool PlayOnStart { get; set; }
Property Value
System.Boolean
|
StartTime
Determines the time (in seconds) at which the audio clip starts playing if Play On Start is enabled.
Declaration
[EditorOrder(51)]
[Limit(0F, 3.40282347E+38F, 0.01F)]
[EditorDisplay("Audio Source", "Start Time")]
[VisibleIf("PlayOnStart", false)]
[Unmanaged]
public float StartTime { get; set; }
Property Value
System.Single
|
State
Gets the current state of the audio playback (playing/paused/stopped).
Declaration
[Unmanaged]
public AudioSource.States State { get; }
Property Value
AudioSource.States
|
UseStreaming
Returns true if audio clip is valid, loaded and uses dynamic data streaming.
Declaration
[Unmanaged]
public bool UseStreaming { get; }
Property Value
System.Boolean
|
Velocity
Gets the velocity of the source. Determines pitch in relation to AudioListener's position. Only relevant for spatial (3D) sources.
Declaration
[Unmanaged]
public Vector3 Velocity { get; }
Property Value
Vector3
|
Volume
Gets or sets the volume of the audio played from this source, in [0, 1] range.
Declaration
[EditorOrder(20)]
[Limit(0F, 1F, 0.01F)]
[EditorDisplay("Audio Source", null)]
[Unmanaged]
public float Volume { get; set; }
Property Value
System.Single
|
Methods
Pause()
Pauses the audio playback.
Declaration
[Unmanaged]
public void Pause()
Play()
Starts playing the currently assigned audio clip.
Declaration
[Unmanaged]
public void Play()
Stop()
Stops audio playback, rewinding it to the start.
Declaration
[Unmanaged]
public void Stop()