Game.Prefabs.WeatherAudioPrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: PrefabBase
Summary:
Represents a prefab used to configure weather-related audio for the game (ambient water sounds and lightning). Exposes editor-serializable fields for assigning EffectPrefab assets and tuning audio behaviour (intensity, fade speed, audible range/zoom and lightning sound speed). When the prefab is initialized into an ECS Entity, it writes a WeatherAudioData component with the configured values and resolves EffectPrefab references to their corresponding entities via the PrefabSystem.
Fields
-
public EffectPrefab m_WaterAmbientAudio
The water ambient audio EffectPrefab to be used. Marked with a Header("Water") and a Tooltip "The water ambient audio clip". Previously serialized as m_SmallWaterAudio. -
public float m_WaterAudioIntensity
The intensity applied to the water audio clip's volume. Tooltip: "The water audio's intensity that will be applied to the audio clip's volume". -
public float m_WaterFadeSpeed
Fade in/out speed for the water audio. Tooltip: "The water audio's fade in & fade out speed". -
public int m_WaterAudioEnabledZoom
Zoom level threshold above which the water audio will not be heard. Tooltip: "The water audio will not be heard when the camera zoom is bigger than it". -
public int m_WaterAudioNearDistance
Near-cell index distance within which the water audio can play. Tooltip: "The near cell's index distance that can play the water audio". -
public float m_LightningSoundSpeed
Lightning sound speed used to affect the perceived delay of lightning audio. Tooltip: "The lightning sound speed that affect the delay". -
public EffectPrefab m_LightningAudio
EffectPrefab for lightning audio. Tooltip: "The lightning audio clip".
Properties
- This class does not define any C# properties.
Constructors
public WeatherAudioPrefab()
Default constructor (Unity/ScriptableObject/Game prefab lifecycle normally instantiates this). No custom constructor logic is provided in the source.
Methods
-
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Overridden but empty in this implementation. Intended to allow adding ECS archetype component types required by this prefab; currently no archetype components are added here. -
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the runtime component types that the prefab requires. This implementation calls the base method and then addsComponentType.ReadWrite<WeatherAudioData>()
, ensuring the entity created from this prefab will have a WeatherAudioData component. -
public override void GetDependencies(List<PrefabBase> prefabs)
Overrides dependency enumeration. This implementation simply calls the base method and does not add extra dependencies. If EffectPrefabs require explicit referencing, PrefabSystem usage in Initialize will resolve them. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is materialized into an ECS Entity. Behavior: - Calls base.Initialize.
- Obtains the PrefabSystem from the entityManager.World to resolve EffectPrefab assets to entities.
- Constructs a WeatherAudioData instance, copying configured values:
- m_WaterFadeSpeed, m_WaterAudioIntensity, m_WaterAudioEnabledZoom, m_WaterAudioNearDistance, m_LightningSoundSpeed
- Resolves m_WaterAmbientAudio and m_LightningAudio into entity references using PrefabSystem.GetEntity(...)
- Writes the WeatherAudioData to the given entity via entityManager.SetComponentData(entity, componentData).
Usage Example
// Example: How the prefab initializes its WeatherAudioData when turned into an Entity.
// (This is essentially what WeatherAudioPrefab.Initialize does internally.)
[Preserve]
public override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity);
var prefabSystem = entityManager.World.GetOrCreateSystemManaged<PrefabSystem>();
var data = new WeatherAudioData
{
m_WaterFadeSpeed = this.m_WaterFadeSpeed,
m_WaterAudioIntensity = this.m_WaterAudioIntensity,
m_WaterAudioEnabledZoom = this.m_WaterAudioEnabledZoom,
m_WaterAudioNearDistance = this.m_WaterAudioNearDistance,
m_WaterAmbientAudio = prefabSystem.GetEntity(this.m_WaterAmbientAudio),
m_LightningAudio = prefabSystem.GetEntity(this.m_LightningAudio),
m_LightningSoundSpeed = this.m_LightningSoundSpeed
};
entityManager.SetComponentData(entity, data);
}
// Example: reading the WeatherAudioData from an entity in a system:
var data = entityManager.GetComponentData<WeatherAudioData>(weatherAudioEntity);
// Use data.m_WaterAmbientAudio (entity ref) and other fields to drive audio playback logic.
If you want, I can also produce an example System that consumes WeatherAudioData to drive audio playback (resolving effect entities to audio sources, applying fade and intensity, and handling lightning delays).