Game.Areas.MapFeatureElement
Assembly: Assembly-CSharp (Game)
Namespace: Game.Areas
Type: struct
Base: IBufferElementData, ISerializable
Summary:
MapFeatureElement is a small ECS buffer element used to represent a map feature's current amount and its regeneration/renewal rate (for example, natural resources on a tile). The struct is marked with InternalBufferCapacity(9), making it suitable for use as a fixed-capacity dynamic buffer on an Entity. It implements Colossal.Serialization.Entities.ISerializable to persist its two float fields, with a version-aware deserialization path for the renewal rate field.
Fields
-
public float m_Amount
This field stores the current amount/value of the map feature (e.g., remaining resource amount). It is serialized first in the Serialize method and deserialized unconditionally in Deserialize. -
public float m_RenewalRate
This field stores the renewal/regeneration rate (per tick/second/unit) for the map feature. It is serialized second in Serialize. During deserialization it is only read when the serialized data's version is at or above Version.naturalResourceRenewalRate; older save formats will not contain this value.
Properties
- (none)
Constructors
public MapFeatureElement(float amount, float regenerationRate)
Constructs a MapFeatureElement initializing m_Amount and m_RenewalRate. Use this to create buffer elements to add to a DynamicBuffer.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the element's data to the provided writer. The method writes m_Amount first, then m_RenewalRate. The writer is expected to implement the IWriter interface used by the game's serialization system. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads data from the provided reader into the fields. m_Amount is always read. m_RenewalRate is conditionally read only if reader.context.version >= Version.naturalResourceRenewalRate, providing backward compatibility with older save formats that lack renewal rate data.
Usage Example
// Add the element to an entity's buffer (in a system or MonoBehaviour that has access to an EntityManager)
var element = new MapFeatureElement(100f, 0.02f); // amount = 100, renewal rate = 0.02
var buffer = entityManager.GetBuffer<MapFeatureElement>(someEntity);
buffer.Add(element);
// Example: iterate buffer and apply renewal each tick in a system
for (int i = 0; i < buffer.Length; i++)
{
var e = buffer[i];
e.m_Amount += e.m_RenewalRate * deltaTime;
buffer[i] = e;
}