Skip to content

Game.Areas.CurrentDistrict

Assembly: Assembly-CSharp (game/mod)
Namespace: Game.Areas

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents a component that stores a reference to the "current" district as an ECS Entity. This struct is a lightweight, value-type component intended for use with Unity's DOTS/ECS in Cities: Skylines 2. It also implements ISerializable so the district reference can be written to and read from game save/serialization streams.


Fields

  • public Unity.Entities.Entity m_District
    Holds the Entity handle for the district. This is the actual reference used by systems to identify the district associated with the entity that carries this component. When default-constructed, the Entity will be the default (invalid) value.

Properties

  • None. This struct exposes its data via the public field above.

Constructors

  • public CurrentDistrict(Unity.Entities.Entity district)
    Creates a CurrentDistrict component with the provided district Entity. Use this to set the district reference when adding the component to an entity.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the contained Entity (m_District) to the provided writer. The writer is expected to handle Entity serialization semantics used by the game's save system.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads an Entity value from the provided reader and stores it in m_District. The reader is expected to map stored identifiers back to runtime Entity handles as appropriate.

Usage Example

// Example: create and add the component to an entity using an EntityManager
var districtEntity = /* obtain or create a district entity */;
var someEntity = /* the entity that should reference the current district */;

var currentDistrict = new Game.Areas.CurrentDistrict(districtEntity);
entityManager.AddComponentData(someEntity, currentDistrict);

// Example: reading the value inside a System
public partial class ExampleSystem : SystemBase
{
    protected override void OnUpdate()
    {
        Entities
            .WithAll<Game.Areas.CurrentDistrict>()
            .ForEach((ref Game.Areas.CurrentDistrict cd) =>
            {
                Unity.Entities.Entity referencedDistrict = cd.m_District;
                // Use referencedDistrict in system logic...
            }).Schedule();
    }
}

// Serialization is handled by the component's Serialize/Deserialize methods
// used by the game's save/load infrastructure; no additional calls are required
// when the component is present on saved entities.