Game.Objects.Plant
Assembly: Game (inferred from project file path)
Namespace: Game.Objects
Type: struct (value type)
Base: System.ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable
Summary: Represents a simple ECS component that stores a single pollution value for a plant object. This struct is intended for use with Unity's DOTS/ECS in Cities: Skylines 2 modding. It is blittable (contains only a single float), implements serialization to/read from the Colossal.Serialization system, and can be used as a query type parameter in entity queries.
Fields
public float m_Pollution
Stores the pollution value associated with this plant. Typical usage is to hold a per-entity pollution contribution or measurement. Default value is 0.0f if not set. This field is serialized/deserialized by the implemented ISerializable methods.
Properties
- None
Constructors
- Implicit default constructor (public Plant())
Structs have an implicit parameterless constructor that initializes m_Pollution to 0.0f. You can also construct explicitly using object initializer syntax, e.g.
new Plant { m_Pollution = 5f }
.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_Pollution value to the provided writer. Used by the Colossal.Serialization framework when saving component data. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads m_Pollution from the provided reader. Used by the Colossal.Serialization framework when loading component data.
Notes: - The generic constraints require a writer/reader implementing IWriter/IReader from Colossal.Serialization.Entities. - Because the type is a simple struct with a single float field, serialization is straightforward and efficient. - Keep the serialized layout stable: changing field ordering or adding/removing fields will affect save/load compatibility.
Usage Example
// Add component to an entity
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = entityManager.CreateEntity();
entityManager.AddComponentData(e, new Plant { m_Pollution = 12.5f });
// Serialize (example wrapper)
void SavePlant<TWriter>(TWriter writer, in Plant plant) where TWriter : IWriter
{
plant.Serialize(writer);
}
// Deserialize (example wrapper)
void LoadPlant<TReader>(TReader reader, out Plant plant) where TReader : IReader
{
plant = new Plant();
plant.Deserialize(reader);
}
Additional tips: - Use this component in systems that read/write pollution values; it is cheap to store and transfer. - When used in queries, the IQueryTypeParameter implementation allows it to participate in DOTS query APIs as expected.