Game.Buildings.BuildingCondition
Assembly: Assembly-CSharp
Namespace: Game.Buildings
Type: struct
Base: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary: Represents a simple ECS component that stores a building's condition as an integer. This struct is intended for use with the Unity Entities (ECS) workflow in Cities: Skylines 2 mods and supports binary serialization via the Colossal.Serialization system. The stored integer typically represents health/condition and is read/written during save/load operations.
Fields
public System.Int32 m_Condition
Holds the building condition value. As a plain int field on a struct, it is blittable and safe to use in jobs and with the Entities API. The meaning and valid range of the value are determined by game logic (commonly a non-negative value where 0 indicates destroyed/ruined).
Properties
- (none)
This struct exposes no properties; use the public field m_Condition directly or wrap it in helper methods if needed.
Constructors
public BuildingCondition()
Default value-type constructor (implicit). When default-constructed, m_Condition == 0. You can also initialize with an object initializer: new BuildingCondition { m_Condition = 100 };
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_Condition value to the provided writer. Called during serialization/save. Implementation calls writer.Write(m_Condition). -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads an integer from the provided reader into m_Condition. Called during deserialization/load. Implementation calls reader.Read(out m_Condition).
Usage Example
// Add a BuildingCondition component to an entity
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var e = entityManager.CreateEntity();
entityManager.AddComponentData(e, new Game.Buildings.BuildingCondition { m_Condition = 100 });
// Read/modify the component later
var cond = entityManager.GetComponentData<Game.Buildings.BuildingCondition>(e);
cond.m_Condition -= 10;
entityManager.SetComponentData(e, cond);
// Example serialize/deserialize usage (pseudocode, depends on IWriter/IReader implementation)
void SaveCondition<TWriter>(in Game.Buildings.BuildingCondition condition, TWriter writer) where TWriter : Colossal.Serialization.Entities.IWriter
{
condition.Serialize(writer);
}
void LoadCondition<TReader>(ref Game.Buildings.BuildingCondition condition, TReader reader) where TReader : Colossal.Serialization.Entities.IReader
{
condition.Deserialize(reader);
}