Skip to content

Game.Events.WeatherPhenomenon

Assembly: Game
Namespace: Game.Events

Type: struct

Base: System.ValueType, implements IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents a weather phenomenon component used by the game's event/weather systems. Stores world-space positions, velocities, radii, intensity and a lightning timer. Implements custom binary (de)serialization with version-aware handling to maintain compatibility with older save/data formats.


Fields

  • public Unity.Mathematics.float3 m_PhenomenonPosition
    World-space center position of the phenomenon (overall effect origin).

  • public Unity.Mathematics.float3 m_HotspotPosition
    Position of the phenomenon's hotspot (local focus within the phenomenon where effects such as lightning or heavier precipitation may originate).

  • public Unity.Mathematics.float3 m_HotspotVelocity
    Velocity of the hotspot; used to move the hotspot over time.

  • public System.Single m_PhenomenonRadius
    Radius (in world units) of the overall phenomenon.

  • public System.Single m_HotspotRadius
    Radius (in world units) of the hotspot area.

  • public System.Single m_Intensity
    Intensity scalar for the phenomenon (affects strength of visual/physical effects).

  • public System.Single m_LightningTimer
    Timer used by the lightning simulation; presence and deserialization depend on the saved data version.

Properties

  • This type does not declare any C# properties. It is a POD-style ECS component with public fields and implements IComponentData for use with the Entities system.

Constructors

  • public WeatherPhenomenon() (implicit)
    As a struct there is the default parameterless constructor. Instantiating without setting fields will yield zeroed/default values. Create and set fields explicitly when adding to an entity.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes all fields to the provided writer in the following order:
  • m_PhenomenonPosition
  • m_HotspotPosition
  • m_HotspotVelocity
  • m_PhenomenonRadius
  • m_HotspotRadius
  • m_Intensity
  • m_LightningTimer

This is the method used by the game's serialization pipeline to persist the component state.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads fields back in the same order as Serialize. The method is version-aware:
  • It always reads the first six fields (positions, velocity, radii, intensity).
  • The lightning timer (m_LightningTimer) is only read if reader.context.version >= Version.lightningSimulation.
  • For intermediate old-version compatibility: if version >= Version.lightningSimulation but < Version.weatherPhenomenonFix, an extra float is read and discarded before reading the lightning timer. This preserves compatibility with an older layout where an obsolete float existed in the serialized stream.

Note: reader.context.version refers to the saved-data/versioning enum used by the game; mods should not assume the presence of lightningTimer unless the save version supports it.

Usage Example

// Example: create a WeatherPhenomenon component and attach it to an entity
using Unity.Entities;
using Unity.Mathematics;
using Game.Events;

var em = World.DefaultGameObjectInjectionWorld.EntityManager;
// Create an entity that holds a WeatherPhenomenon component
var archetype = em.CreateArchetype(typeof(WeatherPhenomenon));
var entity = em.CreateEntity(archetype);

// Initialize the component and set it on the entity
var phenomenon = new WeatherPhenomenon
{
    m_PhenomenonPosition = new float3(100f, 0f, 200f),
    m_HotspotPosition = new float3(102f, 0f, 198f),
    m_HotspotVelocity = new float3(0.5f, 0f, -0.2f),
    m_PhenomenonRadius = 150f,
    m_HotspotRadius = 25f,
    m_Intensity = 0.8f,
    m_LightningTimer = 0f
};
em.SetComponentData(entity, phenomenon);

Additional notes: - Because this is an ECS component (IComponentData), it is intended to be used with ECS systems and queries. Use IQueryTypeParameter or Entities.ForEach / SystemBase queries to operate on instances. - When writing custom save/load code or inspecting save data, respect the version checks in Deserialize to remain compatible with different game versions and historical save layouts.