Search Results for

    Show / Hide Table of Contents

    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.

    Inheritance
    System.Object
    Object
    SceneObject
    Actor
    AudioSource
    Implements
    ISerializable
    Inherited Members
    Actor.SetLayerRecursive(Int32)
    Actor.SetLayerNameRecursive(String)
    Actor.HasTag()
    Actor.HasTag(Tag)
    Actor.HasTag(String)
    Actor.AddTag(Tag)
    Actor.AddTagRecursive(Tag)
    Actor.RemoveTag(Tag)
    Actor.SetParent(Actor, Boolean, Boolean)
    Actor.GetChild(Int32)
    Actor.GetChild(String)
    Actor.GetChild(Type)
    Actor.GetChildren(Type)
    Actor.DestroyChildren(Single)
    Actor.GetScript(Int32)
    Actor.GetScript(Type)
    Actor.GetScripts(Type)
    Actor.AddMovement(Vector3)
    Actor.AddMovement(Vector3, Quaternion)
    Actor.GetWorldToLocalMatrix(Matrix)
    Actor.GetLocalToWorldMatrix(Matrix)
    Actor.OnDebugDraw()
    Actor.OnDebugDrawSelected()
    Actor.GetPrefabRoot()
    Actor.FindActor(String)
    Actor.FindActor(Type, Boolean)
    Actor.FindActor(Type, String)
    Actor.FindActor(Type, Tag, Boolean)
    Actor.FindScript(Type)
    Actor.HasActorInHierarchy(Actor)
    Actor.HasActorInChildren(Actor)
    Actor.IntersectsItself(Ray, Single, Vector3)
    Actor.Intersects(Ray, Single, Vector3)
    Actor.LookAt(Vector3)
    Actor.LookAt(Vector3, Vector3)
    Actor.LookingAt(Vector3)
    Actor.LookingAt(Vector3, Vector3)
    Actor.ToBytes(Actor[])
    Actor.FromBytes(Byte[])
    Actor.FromBytes(Byte[], Dictionary<Guid, Guid>)
    Actor.TryGetSerializedObjectsIds(Byte[])
    Actor.ToJson()
    Actor.FromJson(String)
    Actor.Clone()
    Actor.OnEnable()
    Actor.OnDisable()
    Actor.OnParentChanged()
    Actor.OnTransformChanged()
    Actor.OnActiveChanged()
    Actor.OnActiveInTreeChanged()
    Actor.OnOrderInParentChanged()
    Actor.OnStaticFlagsChanged()
    Actor.OnLayerChanged()
    Actor.OnBeginPlay()
    Actor.OnEndPlay()
    Actor.AddStaticFlags(StaticFlags)
    Actor.RemoveStaticFlags(StaticFlags)
    Actor.SetStaticFlag(StaticFlags, Boolean)
    Actor.HasStaticFlag(StaticFlags)
    Actor.ResetLocalTransform()
    Actor.AddChild(Type)
    Actor.AddChild<T>()
    Actor.GetChild<T>()
    Actor.TryGetChild<T>(T)
    Actor.GetOrAddChild<T>()
    Actor.AddScript(Type)
    Actor.AddScript<T>()
    Actor.GetScript<T>()
    Actor.TryGetScript<T>(T)
    Actor.FindScript<T>()
    Actor.FindActor<T>(Boolean)
    Actor.FindActor<T>(String)
    Actor.FindActor<T>(Tag, Boolean)
    Actor.GetChildren<T>()
    Actor.GetScripts<T>()
    Actor.RotateAround(Vector3, Vector3, Single, Boolean)
    Actor.ToString()
    Actor.Children
    Actor.Tags
    Actor.Layer
    Actor.Name
    Actor.IsActive
    Actor.StaticFlags
    Actor.PerInstanceRandom
    Actor.LocalPosition
    Actor.LocalOrientation
    Actor.LocalScale
    Actor.Sphere
    Actor.Box
    Actor.BoxWithChildren
    Actor.EditorBox
    Actor.EditorBoxChildren
    Actor.HasContentLoaded
    Actor.IsPrefabRoot
    Actor.IsStatic
    Actor.IsTransformStatic
    Actor.WorldToLocalMatrix
    Actor.LocalToWorldMatrix
    SceneObject.SetParent(Actor, Boolean)
    SceneObject.LinkPrefab(Guid, Guid)
    SceneObject.BreakPrefabLink()
    SceneObject.GetNamePath(Char)
    SceneObject.IsDuringPlay
    SceneObject.HasParent
    SceneObject.HasPrefabLink
    SceneObject.PrefabID
    SceneObject.PrefabObjectID
    Object.__unmanagedPtr
    Object.__internalId
    Object.Finalize()
    Object.As<T>()
    Object.NewValue(Type)
    Object.New(String)
    Object.Find<T>(Guid, Boolean)
    Object.Find(Guid, Type, Boolean)
    Object.TryFind<T>(Guid)
    Object.TryFind(Guid, Type)
    Object.Destroy(Object, Single)
    Object.DestroyNow(Object)
    Object.Destroy<T>(T, Single)
    Object.Equals(Object)
    Object.GetUnmanagedPtr(Object)
    Object.GetUnmanagedInterface(Object, Type)
    Object.FromUnmanagedPtr(IntPtr)
    Object.MapObjectID(Guid)
    Object.RemapObjectID(Guid)
    Object.GetHashCode()
    Object.ID
    Object.TypeName
    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()

    Initializes a new instance of the AudioSource.

    Declaration
    public 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()

    Extension Methods

    Extensions.ReflectiveCompare<T>(T, T)
    Extensions.DeepClone<T>(T)
    Extensions.RawClone<T>(T)
    In This Article
    Back to top Copyright © 2012-2024 Wojciech Figat