Game.Simulation.WaterSourceData
Assembly: Game
Namespace: Game.Simulation
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents a water source component used by the simulation ECS. Stores parameters that define a localized water body (constant depth flag/value, available water amount, influence radius, a production/scale multiplier and pollution level). Implements ISerializable to support save/load with version-aware deserialization (m_Polluted is read only when the save version supports water pollution). Typically attached to entities representing water sources/tiles in the simulation.
Fields
-
public int m_ConstantDepth
Specifies whether the water source uses a constant depth (and/or encodes that constant depth value). Interpreted by simulation code when computing water levels or flow; integer storage often indicates a flag or discrete depth level. -
public float m_Amount
The available water amount for this source. Used by water distribution/consumption systems when computing supply, refill, or depletion. -
public float m_Radius
The effective radius of influence for this water source. Determines how far the source affects terrain, supply reach, or how its effects are sampled in nearby cells/entities. -
public float m_Multiplier
A scaling multiplier applied to the water source's effect (production, supply, or visual intensity). Can be used to scale the amount or other computed values without modifying base values. -
public float m_Polluted
Current pollution level of the water source. Read/written by serialization when the save version includes water pollution support. Older save versions may not contain this value; the Deserialize method guards against reading it unless the reader context version is >= Version.waterPollution.
Properties
- None. This type exposes raw public fields and no managed properties.
Constructors
public WaterSourceData()
Default (implicit) constructor produced by the compiler. All numeric fields default to 0 (m_ConstantDepth = 0, m_Amount = 0f, m_Radius = 0f, m_Multiplier = 0f, m_Polluted = 0f). Use an object initializer to set values when creating an instance.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component fields to the provided writer in the following order: m_ConstantDepth, m_Amount, m_Radius, m_Multiplier, m_Polluted. The writer is a generic IWriter implementation provided by the serialization system. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads component fields from the provided reader into the struct's fields. Reads m_ConstantDepth, m_Amount, m_Radius and m_Multiplier unconditionally. m_Polluted is read only if reader.context.version >= Version.waterPollution to maintain backwards compatibility with older save formats. The method uses ref locals to read directly into the fields.
Usage Example
// Add/update a water source component on an entity
var waterSource = new WaterSourceData {
m_ConstantDepth = 1,
m_Amount = 1200f,
m_Radius = 15f,
m_Multiplier = 1.0f,
m_Polluted = 0f
};
entityManager.AddComponentData(entity, waterSource);
// Serialization is handled by the save system. Example pseudocode showing usage:
serializer.WriteComponent(waterSource); // internally calls Serialize<TWriter>