Game.Prefabs.Effects.VehicleSFX
Assembly:
Assembly-CSharp (typical for game scripts / mods — adjust if compiled into a different assembly)
Namespace:
Game.Prefabs.Effects
Type:
class
Base:
ComponentBase
Summary:
VehicleSFX is a prefab component used to configure vehicle-related sound effects. It exposes three float2 fields to define speed ranges and the corresponding pitch and volume mappings. When a prefab with this component is initialized into the ECS world, the component writes a VehicleAudioEffectData component to the entity, copying the configured speed limits, pitch ranges and volume ranges. The class is annotated with a ComponentMenu attribute so it appears under Effects/ in the editor.
Fields
-
public Unity.Mathematics.float2 m_SpeedLimits
Stores the min/max speed range (as a float2) used to map vehicle speed into audio parameters. -
public Unity.Mathematics.float2 m_SpeedPitches
Stores the pitch values (min/max) used for pitch mapping across the speed range. -
public Unity.Mathematics.float2 m_SpeedVolumes
Stores the volume values (min/max) used for volume mapping across the speed range.
Properties
- (none)
This class does not declare public properties. It only exposes public fields and overrides from ComponentBase.
Constructors
public VehicleSFX()
Implicit default constructor. Initialization of the component data is expected to be done in the Unity inspector or by code before the prefab is instantiated. LateInitialize transfers the configured values into the ECS component.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
: System.Void
Adds the ECS component type required by this prefab to the provided hash set. Implementation:-
Adds
ComponentType.ReadWrite<VehicleAudioEffectData>()
so that entities created from the prefab will include the VehicleAudioEffectData component. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
: System.Void
Called during prefab-to-entity conversion / initialization. The method: - Creates a VehicleAudioEffectData instance.
- Copies m_SpeedLimits, m_SpeedPitches and m_SpeedVolumes into that instance.
-
Calls entityManager.SetComponentData(entity, componentData) to write the data to the target entity.
-
public override void GetArchetypeComponents(HashSet<ComponentType> components)
: System.Void
Empty override. Currently does not add any archetype-specific component types.
Additional notes: - The class is decorated with [ComponentMenu("Effects/", new Type[] { typeof(EffectPrefab) })], which places it under Effects/ in the component menu and associates it with EffectPrefab usage. - The primary purpose is to provide data (VehicleAudioEffectData) to runtime systems that drive vehicle sound pitch and volume based on speed.
Usage Example
// Example: how LateInitialize transfers prefab values to the ECS component
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
var componentData = new VehicleAudioEffectData
{
m_SpeedLimits = m_SpeedLimits,
m_SpeedPitches = m_SpeedPitches,
m_SpeedVolumes = m_SpeedVolumes
};
entityManager.SetComponentData(entity, componentData);
}
Notes for modders: - Configure m_SpeedLimits, m_SpeedPitches and m_SpeedVolumes on the prefab in the editor (or via code) to control how vehicle speed maps to audio pitch and volume. - Ensure systems that consume VehicleAudioEffectData are present and expect the same field layout.