Skip to content

Game.Prefabs.DistrictPrefab

Assembly:
{{ Likely part of the main game assembly that contains Game.* types (Cities: Skylines 2 mod/game assemblies). Use the actual assembly name from your project if different. }}

Namespace: Game.Prefabs

Type: class

Base: AreaPrefab

Summary:
DistrictPrefab is a prefab definition for district areas. It configures which ECS components are required for district entities (both prefab-level and archetype-level) and initializes area name color data on the created entity. The class exposes two public Color fields that control the default and selected name colors used for district labels in the game.


Fields

  • public UnityEngine.Color m_NameColor
    This public field defines the default color used for the district name label. Default value: Color.white.

  • public UnityEngine.Color m_SelectedNameColor
    This public field defines the color used for the district name label when the district is selected. Default value: new Color(0.5f, 0.75f, 1f, 1f).

Properties

  • This class does not declare any properties of its own. It overrides methods inherited from AreaPrefab but exposes no automatic properties.

Constructors

  • public DistrictPrefab()
    Default parameterless constructor (implicitly provided). DistrictPrefab relies on Unity/serialization for construction and does not perform special construction logic in code.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the component types that must exist on the prefab entity (runtime components required by the prefab). Implementation:
  • Calls base.GetPrefabComponents(components).
  • Adds the following component types to the provided set:
    • ComponentType.ReadWrite()
    • ComponentType.ReadWrite()
    • ComponentType.ReadWrite()

Purpose: ensures entities created from this prefab have district-specific data components that describe area data and labeling information.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds component types required for the archetype (runtime/per-entity components typically used by systems). Implementation:
  • Calls base.GetArchetypeComponents(components).
  • Adds the following component types:
    • ComponentType.ReadWrite()
    • ComponentType.ReadWrite()
    • ComponentType.ReadWrite()
    • ComponentType.ReadWrite()
    • ComponentType.ReadWrite()
    • ComponentType.ReadWrite()

Purpose: configures the ECS archetype for district entities so systems that read/write these components can operate.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Initializes the entity after creation. Implementation:
  • Calls base.Initialize(entityManager, entity).
  • Sets AreaNameData on the entity with the m_NameColor and m_SelectedNameColor values: entityManager.SetComponentData(entity, new AreaNameData { m_Color = m_NameColor, m_SelectedColor = m_SelectedNameColor });

Purpose: transfers the prefab's Color fields into the runtime ECS AreaNameData component so label rendering and selection coloring use the configured values.

Additional notes: - The class is annotated with [ComponentMenu("Areas/", new Type[] { })], so it appears under the Areas menu in Unity (if used in editor tools). - Relies on Unity.Entities types (ComponentType, EntityManager, Entity) and game-specific data components (DistrictData, AreaNameData, etc.). - The method names are overrides of AreaPrefab and integrate with the game's prefab -> ECS entity initialization pipeline.

Usage Example

// Example: modify the color on a DistrictPrefab instance (e.g. in editor or mod initialization)
DistrictPrefab districtPrefab = /* obtain prefab instance */;
districtPrefab.m_NameColor = Color.yellow;
districtPrefab.m_SelectedNameColor = new Color(0.3f, 0.9f, 0.3f, 1f);

// When the prefab is used to create an entity, Initialize will copy those colors:
// entityManager.SetComponentData(entity, new AreaNameData {
//     m_Color = districtPrefab.m_NameColor,
//     m_SelectedColor = districtPrefab.m_SelectedNameColor
// });

{{Developer tips: If you are creating custom district-like areas, extend AreaPrefab and add/remove component types as needed in GetPrefabComponents/GetArchetypeComponents. Ensure your AreaNameData and label-related components match any custom label rendering systems.}}