Skip to content

Game.Prefabs.Effects.AudioSpot

Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Effects

Type: class

Base: ComponentBase

Summary:
AudioSpot is a prefab component used to attach one-or-more short sound effect prefabs (EffectPrefab SFX) to an effect prefab. At initialization it converts the referenced EffectPrefabs into ECS entities (AudioSourceData entries) and writes the min/max play interval into the AudioSpotData component. It performs editor-time/runtime checks and logs warnings for common misconfigurations (missing SFX components or SFX set to loop). Typical use is to configure an effect prefab in the editor with a list of SFX prefabs and an interval range that the audio system will use at runtime to schedule non-looping sound playback.


Fields

  • public EffectPrefab[] m_SFXes
    Holds references to EffectPrefab objects (the sound effect prefabs) configured in the inspector (attribute shows up as "Sound Effects"). These are converted into ECS entities during LateInitialize and stored in the entity's AudioSourceData buffer.

  • public float m_MinimumInterval
    Minimum value of the playback interval range. This is written into AudioSpotData.m_Interval.x during LateInitialize.

  • public float m_MaximumInterval
    Maximum value of the playback interval range. This is written into AudioSpotData.m_Interval.y during LateInitialize.

Notes: - If m_SFXes is null or empty, LateInitialize logs a warning ("AudioSpot {name} has no sound effects"). - The component does not itself store runtime state beyond converting references into ECS components/buffers; runtime state lives in AudioSpotData and the AudioSourceData buffer on the entity.

Properties

  • None declared on AudioSpot itself. (Runtime data is provided via ECS components: AudioSpotData and a DynamicBuffer on the entity.)

Constructors

  • public AudioSpot()
    No explicit constructor defined in the source — uses the default parameterless constructor. Initialization work that converts references to ECS data is performed in LateInitialize rather than a constructor.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the required ECS component types for this prefab to the given set:
  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite()

This ensures the entity archetype includes AudioSpotData and an AudioSourceData buffer.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Performs prefab -> ECS conversion and validation:
  • Obtains the PrefabSystem.
  • Iterates over m_SFXes:
    • Checks each EffectPrefab's components for an SFX component. If none are found for a given entry, logs: "Warning: AudioSpot {name} has SFX without SFX component".
    • If the SFX component is found and has m_Loop == true, logs a warning that a looping SFX was assigned to an AudioSpot (AudioSpot expects non-looping short sounds).
  • Creates/resizes the DynamicBuffer on the entity to m_SFXes.Length and fills each element's m_SFXEntity by calling PrefabSystem.GetEntity(effectPrefab).
  • Writes AudioSpotData.m_Interval = new float2(m_MinimumInterval, m_MaximumInterval) into the entity.

Important modding notes: - PrefabSystem is used to resolve EffectPrefab -> Entity. Make sure the target EffectPrefabs are included in the mod/package so they can be resolved. - AudioSpot is intended for non-looping SFX. If you need looping audio, use a different approach or ensure the SFX is handled appropriately. - This method logs warnings to help catch misconfigured prefabs.

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds any referenced EffectPrefabs in m_SFXes to the passed dependency list so the prefab system knows to include them when building or loading the prefab.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Empty override in this implementation (no additional archetype components are added here—GetPrefabComponents already declares the required components).

Usage Example

// Typical configuration is done in the editor: assign EffectPrefabs to m_SFXes
// and set the min/max interval values. At runtime/prefab initialization the
// component converts those EffectPrefabs into ECS entities and fills the
// AudioSourceData buffer, and writes the interval into AudioSpotData.

// Example (conceptual) inspector values:
// m_SFXes = [ "BirdChirpEffectPrefab", "WindRustleEffectPrefab" ]
// m_MinimumInterval = 5.0f
// m_MaximumInterval = 15.0f

// LateInitialize will produce:
// AudioSpotData.m_Interval = float2(5.0f, 15.0f)
// AudioSourceData buffer elements will have m_SFXEntity set to the corresponding
// entities resolved via PrefabSystem.GetEntity(effectPrefab)

Additional tips for modders: - Ensure each referenced EffectPrefab actually contains an SFX component (non-looping) — otherwise the AudioSpot logs a warning and that entry is likely useless. - Keep intervals sensible to avoid very frequent effects that may spam audio or performance. - Include all referenced EffectPrefabs in your mod package so PrefabSystem.GetEntity can resolve them at load time.