Game.Buildings.WaterTower
Assembly: Assembly-CSharp (Game)
Namespace: Game.Buildings
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary: Represents the runtime/state component for a water tower building in the ECS world. Stores current stored water amount, amount of polluted water, and a last-known stored-water value used for selection/UI fixes and backwards-compatible save/load. Implements ISerializable so the component can be written to and read from the game's save format.
Fields
-
public int m_StoredWater
Stores the current amount of clean (usable) water in the water tower. -
public int m_Polluted
Stores the current amount of polluted water in the water tower. -
public int m_LastStoredWater
A historic/last-known stored-water value. This field is read/written for compatibility with newer save versions (see Deserialize).
Properties
- This type has no properties.
Constructors
public WaterTower()
Default value-type constructor. All integer fields default to 0. When creating manually, initialize fields explicitly as needed before adding the component to an entity.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component data into the provided writer in the following order: m_StoredWater, m_Polluted, m_LastStoredWater. Used when saving the game. The method writes all three integers unconditionally. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component data from the provided reader. Reads m_StoredWater and m_Polluted unconditionally. For m_LastStoredWater it checks the reader.context.version against Version.waterSelectedInfoFix; m_LastStoredWater is only read if the save version is greater than or equal to that threshold. This preserves backward compatibility with older save files that don't contain the lastStoredWater value.
Notes: - Version.waterSelectedInfoFix is a serialization/versioning constant used by the game to indicate when the lastStoredWater field was introduced into the save format. If the reader's contextual version predates that constant, m_LastStoredWater remains at its default value (0) after deserialization. - This struct is a plain blittable value type suitable for use as an ECS component (IComponentData). Serialization methods rely on the game's generic IWriter/IReader abstractions.
Usage Example
// Create and add a WaterTower component to an entity (using the Unity.Entities API)
var waterTower = new Game.Buildings.WaterTower
{
m_StoredWater = 12000,
m_Polluted = 150,
m_LastStoredWater = 12000
};
entityManager.AddComponentData(entity, waterTower);
// Example: During deserialization the component will be filled by the game's reader.
// The m_LastStoredWater will only be read if the save version >= Version.waterSelectedInfoFix.