Struct AudioDistanceAttenuation | Project Tiny | 0.29.0-preview.22
docs.unity3d.com
    Show / Hide Table of Contents

    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. Minimal code to play an AudioClip with 3d panning and distance-attenuation:

        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
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023