Skip to content

Game.City.MilestoneLevel

Assembly: Assembly-CSharp
Namespace: Game.City

Type: struct (value type)

Base: System.ValueType
Implements: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable

Summary:
MilestoneLevel is a lightweight ECS component that stores the currently achieved milestone for a city as an integer. It is intended to be attached to an Entity (via Unity.Entities) and can be used in queries (IQueryTypeParameter). The struct also supports binary persistence through the Colossal serialization interfaces (Serialize/Deserialize), allowing the milestone value to be saved and loaded with the game's save system.


Fields

  • public int m_AchievedMilestone
    Holds the achieved milestone identifier/level for the city. Default is 0 when the struct is default-initialized. This field is serialized/deserialized by the provided methods. Use this value to check or modify the city's milestone state in ECS systems.

Properties

  • None.
    This type exposes a public field and does not declare properties.

Constructors

  • Implicit parameterless constructor (public MilestoneLevel())
    As a C# struct, it has an implicit default constructor that initializes m_AchievedMilestone to 0. You can initialize with an object initializer: new MilestoneLevel { m_AchievedMilestone = 3 }.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_AchievedMilestone integer to the provided writer. The writer is expected to implement the Colossal IWriter interface (writer.Write(int)).

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads an integer value from the provided reader into m_AchievedMilestone. The reader is expected to implement the Colossal IReader interface (reader.Read(out int)).

Notes: - The serialization methods are simple and forward-compatible only insofar as readers/writers for ints remain compatible; if additional fields are added later, versioning will need to be considered. - Because this is plain data (IComponentData), it is safe to use from jobs and systems following ECS rules (but remember to respect threading and synchronization when reading/writing component data).

Usage Example

// Create and add the component to an entity
var milestone = new MilestoneLevel { m_AchievedMilestone = 2 };
entityManager.AddComponentData(cityEntity, milestone);

// Read/modify in a system
var current = entityManager.GetComponentData<MilestoneLevel>(cityEntity);
if (current.m_AchievedMilestone < 3)
{
    current.m_AchievedMilestone = 3;
    entityManager.SetComponentData(cityEntity, current);
}

// Serialize the component using a writer that implements IWriter
milestone.Serialize(writer);

// Deserialize into a new instance and store on the entity
var loaded = new MilestoneLevel();
loaded.Deserialize(reader);
entityManager.SetComponentData(cityEntity, loaded);