Skip to content

Game.Prefabs.Modes.WeatherPhenomenonMode

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

Type: class

Base: LocalModePrefab

Summary:
WeatherPhenomenonMode is a LocalModePrefab component used to configure and apply mode-specific parameters for weather phenomena (events) to the ECS world. It contains a serializable nested ModeData class array (m_ModeDatas) that holds configurable values such as occurrence probability, temperature/rain bounds, duration, radii, instability, damage severity and danger level. The component provides methods to record the current ECS component values, apply the ModeData values to the corresponding WeatherPhenomenonData ECS components, and restore defaults from the prefab component values.


Fields

  • public ModeData[] m_ModeDatas
    An array of ModeData entries. Each element references an EventPrefab and contains the values to be applied to the corresponding WeatherPhenomenonData ECS component for that event prefab.

Nested class ModeData fields (serializable, public):

  • public EventPrefab m_Prefab
    Reference to the EventPrefab that contains the WeatherPhenomenon component (the target prefab whose ECS component will be modified).

  • public float m_OccurrenceProbability
    Probability that this phenomenon occurs under the configured mode.

  • public Bounds1 m_OccurenceTemperature
    Temperature bounds that govern whether the phenomenon occurs.

  • public Bounds1 m_OccurenceRain
    Rain/precipitation bounds that affect occurrence.

  • public Bounds1 m_Duration
    Bounds for the duration of the phenomenon.

  • public Bounds1 m_PhenomenonRadius
    Bounds for the overall phenomenon radius.

  • public Bounds1 m_HotspotRadius
    Bounds for the hotspot radius inside the phenomenon.

  • public float m_HotspotInstability
    Instability value for hotspot behavior.

  • public float m_DamageSeverity
    Damage severity applied by the phenomenon.

  • public float m_DangerLevel
    Danger level used by the game to weigh threats/alerts.

Properties

  • None (this component exposes data via public fields and overrides methods from LocalModePrefab).

Constructors

  • public WeatherPhenomenonMode()
    Default constructor (Unity will instantiate this component when added to a prefab). Typical initialization is performed via the editor or when the prefab is created/loaded rather than in an explicit constructor.

Methods

  • public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
    Iterates m_ModeDatas, resolves each EventPrefab's WeatherPhenomenon component, obtains the ECS Entity for the prefab, and reads the WeatherPhenomenonData component (entityManager.GetComponentData<WeatherPhenomenonData>(entity)). If the target component is missing on the prefab, a critical log entry is emitted. Primarily used to ensure ECS component access / snapshot current values for change tracking.

  • public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
    For each ModeData entry, resolves the target WeatherPhenomenon prefab and entity, reads the WeatherPhenomenonData from the entity, copies all values from ModeData into the WeatherPhenomenonData struct (occurrence probability, bounds, radii, instability, damage, danger level), and writes the modified component back to the entity with entityManager.SetComponentData. Logs a critical message if the referenced WeatherPhenomenon is not found.

  • public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
    For each ModeData entry, resolves the WeatherPhenomenon component on the referenced prefab and uses the prefab's instance fields (component.m_*) as defaults to overwrite the ECS WeatherPhenomenonData values. Writes the restored values back to the entity. Logs a critical message if the referenced WeatherPhenomenon is not found.

Notes on behavior: - Methods assume PrefabSystem provides a mapping from prefab to ECS Entity. - WeatherPhenomenonData is an ECS IComponentData struct that holds runtime parameters used by the weather/event system. - The component uses ComponentBase.baseLog.Critical to report missing targets.

Usage Example

// Example usage in a setup script or editor code:
public void ConfigureMode(WeatherPhenomenonMode weatherMode,
                          EventPrefab eventPrefab,
                          EntityManager entityManager,
                          PrefabSystem prefabSystem)
{
    // Create a ModeData entry and assign values (Bounds1 construction omitted - use appropriate ctor)
    var modeData = new WeatherPhenomenonMode.ModeData {
        m_Prefab = eventPrefab,
        m_OccurrenceProbability = 0.25f,
        // m_OccurenceTemperature = new Bounds1(minTemp, maxTemp),
        // m_OccurenceRain = new Bounds1(minRain, maxRain),
        // ... fill other fields as required ...
        m_DamageSeverity = 0.5f,
        m_DangerLevel = 1.0f
    };

    weatherMode.m_ModeDatas = new[] { modeData };

    // Apply the configured mode data to the ECS components
    weatherMode.ApplyModeData(entityManager, prefabSystem);
}

This component is typically configured in prefabs (via the editor) rather than constructed at runtime. Use the ApplyModeData and RestoreDefaultData methods to push or revert changes to the in-world ECS component values for the referenced weather event prefabs.