Skip to content

Game.UI.InGame.WorkplacesInfoviewUISystem

Assembly: Assembly-CSharp
Namespace: Game.UI.InGame

Type: class

Base: InfoviewUISystemBase

Summary:
WorkplacesInfoviewUISystem is an ECS-based UI system used by the in-game workplaces infoview. It queries all workplace-related entities (buildings or rented properties that provide work), runs a Burst-compiled IJobChunk to aggregate employment statistics (total workplaces, total workers and detailed EmploymentData), and exposes those aggregated values via GetterValueBinding instances so UI code can bind to keys such as "workplaces", "employees", "workplacesData" and "employeesData". The system uses persistent NativeArray buffers for intermediate results and disposes them on teardown. It also exposes quick "Modified" and "Active" checks for update gating.


Fields

  • private enum Result
    Internal enum used to index/identify results (Workplaces, Employees, Count). Used by the job/results arrays to index totals.

  • private struct CalculateWorkplaceDataJob : IJobChunk
    Burst-compiled job that iterates workplace archetype chunks, reads Employees buffer, WorkProvider, PrefabRef and optional PropertyRenter, and accumulates:

  • m_IntResults: int totals (workplaces and employees)
  • m_EmploymentDataResults: EmploymentData totals for workplaces and employees The job uses ComponentLookup and ComponentType/BufferType handles supplied from the system.

  • private struct TypeHandle
    Helper container holding EntityTypeHandle, BufferTypeHandle, ComponentTypeHandles and ComponentLookups required by the job. Has __AssignHandles to populate handles from a SystemState.

  • private const string kGroup = "workplaces"
    Constant grouping/name used for the binding group ("workplaces").

  • private EntityQuery m_WorkplaceQuery
    Query selecting all workplace entities to be aggregated. Built in OnCreate to require Employee, WorkProvider and PrefabRef, and to include either PropertyRenter or Building, excluding OutsideConnection and Temp.

  • private EntityQuery m_WorkplaceModifiedQuery
    Query used to quickly detect modifications: looks for Employee/WorkProvider/PrefabRef plus Created/Updated/Deleted tags (excludes Temp).

  • private GetterValueBinding<EmploymentData> m_EmployeesData
    Getter binding exposing aggregated employees employment data to the UI under the binding group/keys.

  • private GetterValueBinding<EmploymentData> m_WorkplacesData
    Getter binding exposing aggregated workplaces employment data to the UI.

  • private GetterValueBinding<int> m_Workplaces
    Getter binding exposing total workplaces count (int).

  • private GetterValueBinding<int> m_Workers
    Getter binding exposing total workers count (int).

  • private NativeArray<int> m_IntResults
    Persistent NativeArray (length 2) used to accumulate totals (workplaces, employees). Allocated with Allocator.Persistent and disposed in OnDestroy.

  • private NativeArray<EmploymentData> m_EmploymentDataResults
    Persistent NativeArray (length 2) used to accumulate EmploymentData results for workplaces and employees. Allocated with Allocator.Persistent and disposed in OnDestroy.

  • private TypeHandle __TypeHandle
    Instance of the TypeHandle helper storing handles/lookups for scheduling the job.


Properties

  • protected override bool Active { get; }
    Returns true if base.Active is true or any of the UI bindings are active. Specifically the implementation returns true if either the workplaces or employees binding is active. Used to avoid work when the infoview isn't visible/needed.

  • protected override bool Modified => !m_WorkplaceModifiedQuery.IsEmptyIgnoreFilter
    Fast check that returns true when the workplace modification query is non-empty (Created/Updated/Deleted present), indicating cached results should be recomputed.


Constructors

  • public WorkplacesInfoviewUISystem()
    Default constructor (preserved). The real initialization happens in OnCreate / OnCreateForCompiler. The constructor itself does not allocate the NativeArrays.

Methods

  • protected override void OnCreate()
    Initializes EntityQueries (m_WorkplaceQuery and m_WorkplaceModifiedQuery), allocates m_IntResults and m_EmploymentDataResults with Allocator.Persistent, and registers AddBinding for:
  • workplacesData (EmploymentData)
  • employeesData (EmploymentData)
  • workplaces (int)
  • employees (int) These bindings expose aggregated results to the UI binding system.

  • protected override void OnDestroy()
    Disposes persistent NativeArray allocations (m_IntResults and m_EmploymentDataResults) and calls base.OnDestroy().

  • protected override void PerformUpdate()
    Main update path called by the system scheduler. It:

  • Resets intermediate results to zero/default
  • Schedules (and completes) CalculateWorkplaceDataJob using current TypeHandles and component lookups
  • Calls Update() on each GetterValueBinding to push new values to the binding system This is where the job does the per-chunk aggregation.

  • private void ResetResults()
    Zeroes/initializes both result arrays (m_IntResults and m_EmploymentDataResults) before scheduling the job.

  • private int GetWorkplaces()
    Safe accessor used by the workplaces GetterValueBinding. Returns m_IntResults[0] if arrays are allocated and valid; otherwise returns 0.

  • private int GetWorkers()
    Safe accessor used by the employees GetterValueBinding. Returns m_IntResults[1] if arrays are allocated and valid; otherwise returns 0.

  • private EmploymentData GetWorkplacesData()
    Safe accessor returning aggregated EmploymentData for workplaces (m_EmploymentDataResults[0]) or default(EmploymentData) if unavailable.

  • private EmploymentData GetEmployeesData()
    Safe accessor returning aggregated EmploymentData for employees (m_EmploymentDataResults[1]) or default(EmploymentData) if unavailable.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Compiler/IL-compat helper called from OnCreateForCompiler; builds/assigns queries if needed (in this class it constructs an EntityQueryBuilder and disposes it — stubbed for compiler paths).

  • protected override void OnCreateForCompiler()
    Called in some build/runtime/compatibility scenarios to assign queries and assign type handles via __TypeHandle.__AssignHandles(ref base.CheckedStateRef).

  • (Nested) CalculateWorkplaceDataJob.Execute(in ArchetypeChunk chunk, ...)
    The job's Execute reads:

  • Entities' PrefabRef/WorkProvider/PropertyRenter and Employees buffer
  • Resolves spawnable building level if the PropertyRenter refers to a spawnable property
  • Calls EmploymentData.GetWorkplacesData and GetEmployeesData to compute per-building EmploymentData
  • Accumulates totals into the provided NativeArray fields The job is Burst-compiled and scheduled via JobChunkExtensions.

Notes and important behaviors: - NativeArray allocations are persistent; forgetting to dispose them would leak unmanaged memory. This system disposes them in OnDestroy. - The job uses ComponentLookup (ComponentFromEntity-like operations) to resolve prefab-based data (WorkplaceData, SpawnableBuildingData). - The system uses the Modified property to quickly short-circuit updates if no relevant entity changes occurred (via m_WorkplaceModifiedQuery). - The job accounts for building levels when calculating workplace capacities by resolving spawnable building data when a PropertyRenter links to a spawnable building prefab.

Usage Example

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

    // allocate result arrays (this mirrors what WorkplacesInfoviewUISystem does)
    m_IntResults = new NativeArray<int>(2, Allocator.Persistent);
    m_EmploymentDataResults = new NativeArray<EmploymentData>(2, Allocator.Persistent);

    // add bindings so UI can read aggregated values under the "workplaces" group
    AddBinding(m_WorkplacesData = new GetterValueBinding<EmploymentData>(
        "workplaces", "workplacesData", GetWorkplacesData, new ValueWriter<EmploymentData>()));
    AddBinding(m_EmployeesData = new GetterValueBinding<EmploymentData>(
        "workplaces", "employeesData", GetEmployeesData, new ValueWriter<EmploymentData>()));
    AddBinding(m_Workplaces = new GetterValueBinding<int>("workplaces", "workplaces", GetWorkplaces));
    AddBinding(m_Workers = new GetterValueBinding<int>("workplaces", "employees", GetWorkers));
}

If you need, I can: - Produce a shorter quick-reference with only the public API and important remarks, or - Produce a more detailed walkthrough of the CalculateWorkplaceDataJob logic and how EmploymentData values are computed and interpreted.