Game.Prefabs.AudioSettingsPrefab
Assembly:
Assembly-CSharp (game assembly)
Namespace:
Game.Prefabs
Type:
class
Base:
PrefabBase
Summary:
Prefab used to configure ambient audio and audio culling behaviour for the game. Exposes an array of audio effect prefabs and settings for ambient audio (min/max height, overlap and distance ratios). Also provides culling limits for different audio categories (fire, car engine, public transport). The prefab adds ECS component types and populates component data and buffers when converted into an Entity via LateInitialize.
Fields
-
public EffectPrefab[] m_Effects
Array of EffectPrefab references. Each entry is converted into an AmbientAudioEffect in the entity buffer during LateInitialize. -
public float m_MinHeight
Minimum height used by ambient audio settings (copied to AmbientAudioSettingsData.m_MinHeight). -
public float m_MaxHeight
Maximum height used by ambient audio settings (copied to AmbientAudioSettingsData.m_MaxHeight). -
[Range(0f, 1f)] public float m_OverlapRatio = 0.8f
Overlap ratio for ambient audio (clamped to 0..1). Copied to AmbientAudioSettingsData.m_OverlapRatio. -
[Range(0f, 1f)] public float m_MinDistanceRatio = 0.5f
Minimum distance ratio for ambient audio (clamped to 0..1). Copied to AmbientAudioSettingsData.m_MinDistanceRatio. -
public int m_FireCullMaxAmount
Maximum number of fire-related audio instances allowed (copied to CullingAudioSettingsData.m_FireCullMaxAmount). -
public float m_FireCullMaxDistance
Max distance for fire audio culling (copied to CullingAudioSettingsData.m_FireCullMaxDistance). -
public int m_CarEngineCullMaxAmount
Maximum number of car engine audio instances allowed (copied to CullingAudioSettingsData.m_CarEngineCullMaxAmount). -
public float m_CarEngineCullMaxDistance
Max distance for car engine audio culling (copied to CullingAudioSettingsData.m_CarEngineCullMaxDistance). -
public int m_PublicTransCullMaxAmount
Maximum number of public transport audio instances allowed (copied to CullingAudioSettingsData.m_PublicTransCullMaxAmount). -
public float m_PublicTransCullMaxDistance
Max distance for public transport audio culling (copied to CullingAudioSettingsData.m_PublicTransCullMaxDistance).
Properties
- (none declared on this type)
Constructors
public AudioSettingsPrefab()
Default constructor (inherited behavior from Unity/MonoBehaviour/PrefabBase). Instances are typically configured in the Unity Inspector.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the ECS component types required by this prefab to the provided set. Specifically adds:- AmbientAudioSettingsData (ReadWrite)
- AmbientAudioEffect (ReadWrite) — used as a DynamicBuffer element
-
CullingAudioSettingsData (ReadWrite)
This lets the prefab system know which components/buffers must exist on the Entity. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Populates the Entity with runtime component data and buffers: - Obtains the DynamicBuffer
on the entity and fills it with entries for each m_Effects item. Each entry's m_Effect field is set to the Entity corresponding to the EffectPrefab (resolved via PrefabSystem.GetEntity). - Constructs and sets an AmbientAudioSettingsData component using the prefab's m_MinHeight, m_MaxHeight, m_OverlapRatio and m_MinDistanceRatio fields.
- Constructs and sets a CullingAudioSettingsData component using the prefab's culling-related fields (fire, car engine, public transport amounts and distances).
This method is called during prefab-to-entity conversion to transfer inspector values into ECS components.
Usage Example
// Example: obtain the entity created from an AudioSettingsPrefab and read its settings
var prefabSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged<PrefabSystem>();
Entity audioPrefabEntity = prefabSystem.GetEntity(myAudioSettingsPrefab); // myAudioSettingsPrefab is an AudioSettingsPrefab reference
// Read ambient audio settings
var ambientSettings = entityManager.GetComponentData<AmbientAudioSettingsData>(audioPrefabEntity);
// Read culling settings
var cullingSettings = entityManager.GetComponentData<CullingAudioSettingsData>(audioPrefabEntity);
// Read the list of ambient audio effects (buffer contains AmbientAudioEffect elements)
var effectsBuffer = entityManager.GetBuffer<AmbientAudioEffect>(audioPrefabEntity);
for (int i = 0; i < effectsBuffer.Length; i++)
{
Entity effectEntity = effectsBuffer[i].m_Effect;
// Use effectEntity (e.g., resolve its EffectPrefab or process audio effect data)
}
Notes: - The prefab must be converted through the game's PrefabSystem (or similar conversion pipeline) so LateInitialize runs and the entity receives the components. - m_OverlapRatio and m_MinDistanceRatio are constrained to [0,1] via the Range attribute in the inspector.