Skip to content

Game.UI.InGame.LevelInfoviewUISystem

Assembly:
Assembly-CSharp.dll

Namespace:
Game.UI.InGame

Type:
class

Base:
InfoviewUISystemBase

Summary:
LevelInfoviewUISystem is an in-game UI system that gathers building level distributions for different building types (Residential, Commercial, Industrial and Office) using Unity's Entities (ECS) and Jobs system. It schedules a Burst-compiled IJobChunk (UpdateLevelsJob) across a query of spawnable building entities, aggregates level counts into a NativeArray of "Levels" results, and exposes those results via RawValueBindings to the UI as five-slice pie chart data. The system filters out deleted or temporary entities and ignores signature buildings. It is intended for use within Cities: Skylines 2 modding to populate the level distribution infoview.


Fields

  • private enum Result
    Enumerates the result slots used internally (Residential, Commercial, Industrial, Office, ResultCount). Used to index into the m_Results NativeArray.

  • private RawValueBinding m_ResidentialLevels
    Binding that provides residential level distribution data to the UI (key "levelInfo" / "residential").

  • private RawValueBinding m_CommercialLevels
    Binding that provides commercial level distribution data to the UI (key "levelInfo" / "commercial").

  • private RawValueBinding m_IndustrialLevels
    Binding that provides industrial level distribution data to the UI (key "levelInfo" / "industrial").

  • private RawValueBinding m_OfficeLevels
    Binding that provides office level distribution data to the UI (key "levelInfo" / "office").

  • private EntityQuery m_SpawnableQuery
    EntityQuery used to find all building entities that are spawnable and relevant for level counting (includes Building + PrefabRef and any of ResidentialProperty/CommercialProperty/IndustrialProperty, excludes Deleted and Temp).

  • private NativeArray<Levels> m_Results
    NativeArray of 4 Levels structs used to accumulate counts for each category (index 0..3 correspond to Result enum entries). Allocated with Allocator.Persistent and disposed on destroy.

  • private TypeHandle __TypeHandle
    Container for component type handles and lookups used by the job. Assigned in OnCreateForCompiler and updated via InternalCompilerInterface when scheduling the job.

  • private struct UpdateLevelsJob (nested)
    Burst-compiled IJobChunk that iterates archetype chunks, reads PrefabRef and property components, looks up spawnable building data, and increments the appropriate Levels counters for each building matched. Skips signature buildings and uses ComponentLookup to detect office buildings for the industrial vs office distinction.

  • private struct Levels (nested)
    Simple POD struct holding five integer counters (Level1..Level5) and defines an operator+ used to aggregate per-chunk results into the m_Results array.

  • private struct TypeHandle (nested)
    Holds ComponentTypeHandle and ComponentLookup instances; provides __AssignHandles to initialize them from a SystemState.

Properties

  • protected override bool Active { get; }
    Returns true if the system or any of the four RawValueBindings is active. The override ensures the system is considered active only when it or any individual binding has been enabled.

Constructors

  • public LevelInfoviewUISystem()
    Default constructor. The real initialization happens in OnCreate; this constructor is attributed with [Preserve] in the source to avoid stripping.

Methods

  • protected override void OnCreate()
    Initializes the EntityQuery (m_SpawnableQuery), registers four RawValueBindings for residential/commercial/industrial/office level data, and allocates the m_Results NativeArray with 4 elements. Marked with [Preserve].

  • protected override void OnDestroy()
    Disposes the m_Results NativeArray and calls base.OnDestroy(). Marked with [Preserve].

  • protected override void PerformUpdate()
    Called by the system update loop; calls UpdateBindings() to recompute and push UI values.

  • protected override void OnGameLoaded(Context serializationContext)
    Invoked when a game is loaded; triggers an UpdateBindings() to ensure UI is up to date after load.

  • private void UpdateBindings()
    Core routine that zeroes the m_Results, prepares and schedules the UpdateLevelsJob using component handles/lookups from __TypeHandle, completes the job, and then updates each RawValueBinding so the UI receives the latest data.

  • private void UpdateResidentialLevels(IJsonWriter writer)
    Writes residential level distribution into the provided JSON writer by pulling the aggregated Levels from m_Results[0] and calling WriteLevels.

  • private void UpdateCommercialLevels(IJsonWriter writer)
    Writes commercial level distribution into the provided JSON writer (m_Results[1]).

  • private void UpdateIndustrialLevels(IJsonWriter writer)
    Writes industrial level distribution into the provided JSON writer (m_Results[2]).

  • private void UpdateOfficeLevels(IJsonWriter writer)
    Writes office level distribution into the provided JSON writer (m_Results[3]).

  • private void WriteLevels(IJsonWriter writer, Levels levels)
    Helper that forwards the five level counts to InfoviewsUIUtils.UpdateFiveSlicePieChartData to construct the UI pie chart JSON payload.

  • private void __AssignQueries(ref SystemState state)
    Compiler-inserted helper for queries; no-op in this decompiled view except for creating/disposing a temp EntityQueryBuilder. Marked MethodImplOptions.AggressiveInlining.

  • protected override void OnCreateForCompiler()
    Compiler helper method: calls base.OnCreateForCompiler, assigns queries and calls __TypeHandle.__AssignHandles using the system's CheckedStateRef. Used by generated code paths.

  • public LevelInfoviewUISystem()
    [Preserve] parameterless constructor (listed again in source); included to indicate constructed via default ctor.

  • UpdateLevelsJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) (nested job method)
    Per-chunk work: iterates PrefabRef entries in the chunk, fetches spawnable building data from component lookup, filters signature buildings, checks presence of residential/commercial/industrial properties and whether an industrial building is actually an office, and increments appropriate Levels counters per chunk. Aggregates per-chunk counters into the job's NativeArray m_Results.

  • UpdateLevelsJob.AddLevel(SpawnableBuildingData spawnableBuildingData, ref Levels levels) (nested job helper)
    Increments the appropriate LevelX counter in the provided Levels struct based on spawnableBuildingData.m_Level (1..5).


Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Example of what this system does in OnCreate: it creates an EntityQuery and registers bindings
    m_SpawnableQuery = GetEntityQuery(new EntityQueryDesc
    {
        All = new ComponentType[2]
        {
            ComponentType.ReadOnly<Building>(),
            ComponentType.ReadOnly<PrefabRef>()
        },
        Any = new ComponentType[3]
        {
            ComponentType.ReadOnly<ResidentialProperty>(),
            ComponentType.ReadOnly<CommercialProperty>(),
            ComponentType.ReadOnly<IndustrialProperty>()
        },
        None = new ComponentType[2]
        {
            ComponentType.ReadOnly<Deleted>(),
            ComponentType.ReadOnly<Temp>()
        }
    });

    AddBinding(m_ResidentialLevels = new RawValueBinding("levelInfo", "residential", UpdateResidentialLevels));
    AddBinding(m_CommercialLevels = new RawValueBinding("levelInfo", "commercial", UpdateCommercialLevels));
    AddBinding(m_IndustrialLevels = new RawValueBinding("levelInfo", "industrial", UpdateIndustrialLevels));
    AddBinding(m_OfficeLevels = new RawValueBinding("levelInfo", "office", UpdateOfficeLevels));

    m_Results = new NativeArray<Levels>(4, Allocator.Persistent);
}

If you want, I can also: - Extract and document the nested UpdateLevelsJob and Levels structs in a separate section with field-by-field documentation. - Provide an example of how the JSON output looks for the UI pie chart (the expected shape written by InfoviewsUIUtils.UpdateFiveSlicePieChartData).