Game.Prefabs.VehicleAudioEffectData
Assembly:
Assembly-CSharp (game code / mod assembly)
Namespace:
Game.Prefabs
Type:
struct (implements IComponentData, IQueryTypeParameter)
Base:
System.ValueType
Summary:
Component data used by vehicle prefabs to describe how audio effects (pitch and volume) should vary with vehicle speed. Holds three float2 fields that represent min/max speed limits and the corresponding pitch and volume values for those limits. Typically consumed by audio systems that sample or interpolate pitch/volume based on current vehicle speed.
Fields
-
public Unity.Mathematics.float2 m_SpeedLimits
Lower (x) and upper (y) speed limits used as the reference range for mapping speed to audio parameters. Values are in the game's speed units (context-dependent). -
public Unity.Mathematics.float2 m_SpeedPitches
Pitch values corresponding to the lower (x) and upper (y) entries of m_SpeedLimits. Audio systems commonly interpolate between these two pitch values based on current speed. -
public Unity.Mathematics.float2 m_SpeedVolumes
Volume values corresponding to the lower (x) and upper (y) entries of m_SpeedLimits. Audio systems commonly interpolate between these two volume values based on current speed.
Properties
- None (this is a plain IComponentData struct with public fields)
Constructors
- Implicit default constructor (generated by the compiler) — you can initialize fields directly when creating an instance.
Methods
- None (no methods are defined; this struct is pure data)
Usage Example
// Example: create an entity with this component via an EntityManager
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var archetype = entityManager.CreateArchetype(typeof(Game.Prefabs.VehicleAudioEffectData));
var entity = entityManager.CreateEntity(archetype);
entityManager.SetComponentData(entity, new Game.Prefabs.VehicleAudioEffectData
{
m_SpeedLimits = new Unity.Mathematics.float2(0f, 100f), // min/max speed
m_SpeedPitches = new Unity.Mathematics.float2(0.9f, 1.2f), // pitch at min/max
m_SpeedVolumes = new Unity.Mathematics.float2(0.2f, 1.0f) // volume at min/max
});
// Example usage inside a SystemBase to read and apply interpolation:
Entities.ForEach((ref AudioComponent audio, in Game.Prefabs.VehicleAudioEffectData vfx, in VehicleSpeed speed) =>
{
float s = math.clamp(speed.Value, vfx.m_SpeedLimits.x, vfx.m_SpeedLimits.y);
float t = (vfx.m_SpeedLimits.y > vfx.m_SpeedLimits.x)
? (s - vfx.m_SpeedLimits.x) / (vfx.m_SpeedLimits.y - vfx.m_SpeedLimits.x)
: 0f;
audio.Pitch = math.lerp(vfx.m_SpeedPitches.x, vfx.m_SpeedPitches.y, t);
audio.Volume = math.lerp(vfx.m_SpeedVolumes.x, vfx.m_SpeedVolumes.y, t);
}).ScheduleParallel();