Game.Prefabs.AudioEffectData
Assembly:
{{ Typically defined in the game's runtime assembly containing prefabs and ECS components. }}
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter
Summary:
AudioEffectData is a plain data (IComponentData) container used by the ECS to describe spatial audio effect parameters for an entity. It holds an identifier for the audio clip, the maximum audible distance, the physical source size, and fade timings. Because it implements IQueryTypeParameter it can be used directly in Entity query type parameters in DOTS systems.
Fields
-
public int m_AudioClipId
Identifier for the audio clip to play. The meaning of the integer depends on the game's audio registry (e.g., an index or resource id). Use the same id mapping the game audio system expects. -
public float m_MaxDistance
Maximum distance (in world units) at which the audio effect can be heard. Beyond this distance the audio is typically culled or attenuated to silence. -
public float3 m_SourceSize
Physical size of the sound source (width, height, depth) in world units. Used for spatialization/attenuation calculations and for approximating the area the sound originates from. -
public float2 m_FadeTimes
A pair of fade durations (in seconds). Common convention: x = fadeIn time, y = fadeOut time. These control how quickly the audio ramps up and down when starting/stopping or entering/exiting effective range.
Properties
- This type defines no properties. It is a plain value-type component with public fields.
Constructors
public AudioEffectData()
There is no explicit constructor declared in the source; the C# compiler provides a default parameterless constructor for the struct. Create and initialize using object initializer syntax when adding the component.
Methods
- This type declares no methods. It's a data-only component intended to be read/modified by systems.
Usage Example
// Example: create an entity and add AudioEffectData to it
using Unity.Entities;
using Unity.Mathematics;
using Game.Prefabs;
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = em.CreateEntity();
// Set up audio effect parameters
var audioData = new AudioEffectData
{
m_AudioClipId = 42, // clip id from game's audio registry
m_MaxDistance = 60f, // audible up to 60 world units
m_SourceSize = new float3(1f, 2f, 1f), // approximate source dimensions
m_FadeTimes = new float2(0.5f, 1.5f) // 0.5s fade in, 1.5s fade out
};
em.AddComponentData(entity, audioData);
// AudioEffectData can also be used directly in queries due to IQueryTypeParameter:
// e.g. Entities.WithoutBurst().ForEach((Entity e, ref AudioEffectData a) => { ... });