Skip to content

Game.CompanyInfoviewUISystem

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

Type: class CompanyInfoviewUISystem

Base: InfoviewUISystemBase

Summary:
UI system for the in-game company info view. It exposes three profitability indicators (commercial, industrial, office) to the UI by binding GetterValueBinding entries to the "companyInfoview" UI group. The system queries ECS entities that represent companies (commercial/industrial) and computes average profitability values. It depends on the ResourceSystem and uses ComponentLookup access to prefab/resource/industrial-process components to filter entities (especially for differentiating office vs industrial outputs).


Fields

  • private struct TypeHandle
    Contains ComponentLookup fields for PrefabRef, ResourceData and IndustrialProcessData and an __AssignHandles method to initialize them from a SystemState. Used to obtain component lookups in a way compatible with the ECS CheckedStateRef.

  • public ComponentLookup<PrefabRef> __Game_Prefabs_PrefabRef_RO_ComponentLookup
    Read-only lookup for PrefabRef components.

  • public ComponentLookup<ResourceData> __Game_Prefabs_ResourceData_RO_ComponentLookup
    Read-only lookup for ResourceData components.

  • public ComponentLookup<IndustrialProcessData> __Game_Prefabs_IndustrialProcessData_RO_ComponentLookup
    Read-only lookup for IndustrialProcessData components.

  • private const string kGroup
    Constant "companyInfoview" — the UI group key this system binds to.

  • private ResourceSystem m_ResourceSystem
    Reference to the ResourceSystem (acquired from the World) used to access resource prefabs and weights.

  • private EntityQuery m_CommercialQuery
    ECS EntityQuery that selects commercial companies (Profitability, PropertyRenter, CommercialCompany).

  • private EntityQuery m_IndustrialQuery
    ECS EntityQuery that selects industrial companies (Profitability, PropertyRenter, IndustrialCompany).

  • private GetterValueBinding<IndicatorValue> m_CommercialProfitability
    UI binding for the commercial profitability indicator (key "commercialProfitability").

  • private GetterValueBinding<IndicatorValue> m_IndustrialProfitability
    UI binding for the industrial profitability indicator (key "industrialProfitability").

  • private GetterValueBinding<IndicatorValue> m_OfficeProfitability
    UI binding for the office profitability indicator (key "officeProfitability").

  • private TypeHandle __TypeHandle
    Instance of the TypeHandle struct used to fetch ComponentLookup objects at runtime.

Properties

  • protected override bool Active { get; }
    Returns true if the base system is active or any of the three GetterValueBinding instances (commercial, industrial, office) are active. The logic: if base.Active is false and both commercial and industrial bindings are inactive, then returns office binding's active state; otherwise returns true. This ensures the system stays enabled while any relevant UI bindings are active.

Constructors

  • public CompanyInfoviewUISystem()
    Parameterless constructor. The class is CompilerGenerated with Preserve attributes on lifecycle methods; initialization of runtime resources happens in OnCreate.

Methods

  • [Preserve] protected override void OnCreate()
    Initializes the system:
  • Acquires ResourceSystem via base.World.GetOrCreateSystemManaged().
  • Builds EntityQuery instances:
    • m_CommercialQuery: Profitability + PropertyRenter + CommercialCompany
    • m_IndustrialQuery: Profitability + PropertyRenter + IndustrialCompany
  • Registers UI bindings:
    • m_CommercialProfitability bound to "companyInfoview" / "commercialProfitability" calling GetCommercialProfitability
    • m_IndustrialProfitability bound to "companyInfoview" / "industrialProfitability" calling GetIndustrialProfitability
    • m_OfficeProfitability bound to "companyInfoview" / "officeProfitability" calling GetOfficeProfitability

These bindings use GetterValueBinding with a ValueWriter.

  • protected override void PerformUpdate()
    Updates each registered UI binding by calling Update() on m_CommercialProfitability, m_IndustrialProfitability and m_OfficeProfitability. This pushes new IndicatorValue values to the UI when needed.

  • private IndicatorValue GetCommercialProfitability()
    Computes the average Profitability.m_Profitability over all entities matched by m_CommercialQuery:

  • Converts query to NativeArray with Allocator.TempJob.
  • Iterates entities, tries to read Profitability component via EntityManager.TryGetComponent.
  • Sums profitability values and counts entities that had a Profitability component.
  • Disposes the NativeArray in a finally block.
  • Returns IndicatorValue(min: 0f, max: 255f, current: averageProfitability). If no entities, current is 0f.

  • private IndicatorValue GetOfficeProfitability()
    Computes "office" profitability from the industrial query by filtering industrial-prefab entities whose industrial process output resource has zero weight (i.e., not a real resource output). Key points:

  • Obtains ResourcePrefabs from m_ResourceSystem.GetPrefabs().
  • Gets nativeArray from m_IndustrialQuery (Allocator.TempJob).
  • Retrieves ComponentLookup instances for PrefabRef, ResourceData and IndustrialProcessData using InternalCompilerInterface.GetComponentLookup and the stored __TypeHandle lookups.
  • Iterates entities and:
    • Ensures entity has Profitability and a PrefabRef component.
    • Retrieves the prefab (PrefabRef.m_Prefab) and checks for IndustrialProcessData on that prefab.
    • For prefabs with industrial process, evaluates EconomyUtils.GetWeight for the process output resource; if the weight is effectively zero (Math.Abs(...) <= float.Epsilon), treats it as an "office" (no resource output) and includes it in the average.
  • Returns IndicatorValue(0f, 255f, average) and disposes the NativeArray.

  • private IndicatorValue GetIndustrialProfitability()
    Computes industrial profitability by including only industrial-prefab entities that have a non-zero output weight:

  • Similar pattern to GetOfficeProfitability: obtain NativeArray from m_IndustrialQuery and ComponentLookup instances for PrefabRef, ResourceData, IndustrialProcessData.
  • For each entity with Profitability and a PrefabRef:
    • If the prefab has IndustrialProcessData, fetch industrialProcessData and compute the resource output weight via EconomyUtils.GetWeight.
    • If the weight is not effectively zero (abs >= epsilon), include that entity's profitability in the average.
  • Returns IndicatorValue(0f, 255f, average) and disposes the NativeArray.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Placeholder/auto-generated: constructs and disposes a temporary EntityQueryBuilder (no explicit queries assigned here). Used by compiler-generated OnCreateForCompiler.

  • protected override void OnCreateForCompiler()
    Compiler helper method called during creation in AOT/compiled contexts:

  • Calls base.OnCreateForCompiler().
  • Calls __AssignQueries(ref base.CheckedStateRef) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to initialize the component lookups used by the system.

  • private void __TypeHandle.__AssignHandles(ref SystemState state)
    Method inside TypeHandle struct — assigns the ComponentLookup instances using state.GetComponentLookup(isReadOnly: true) for PrefabRef, ResourceData, IndustrialProcessData.

Notes on implementation details and safety: - NativeArray allocations use Allocator.TempJob and are properly disposed in finally blocks to avoid leaks. - ComponentLookup access is done via InternalCompilerInterface.GetComponentLookup with __TypeHandle and the CheckedStateRef to ensure safe lookup in systems with incremental safety checks. - Profitability values are averaged as integers (sum of m_Profitability, count), then converted to float for IndicatorValue. The indicator's min/max are set to 0 and 255 to match profitability range.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Acquire resource system and prepare queries & bindings
    m_ResourceSystem = base.World.GetOrCreateSystemManaged<ResourceSystem>();
    m_CommercialQuery = GetEntityQuery(ComponentType.ReadOnly<Profitability>(),
                                       ComponentType.ReadOnly<PropertyRenter>(),
                                       ComponentType.ReadOnly<CommercialCompany>());
    m_IndustrialQuery = GetEntityQuery(ComponentType.ReadOnly<Profitability>(),
                                       ComponentType.ReadOnly<PropertyRenter>(),
                                       ComponentType.ReadOnly<IndustrialCompany>());

    AddBinding(m_CommercialProfitability = new GetterValueBinding<IndicatorValue>(
        "companyInfoview", "commercialProfitability", GetCommercialProfitability, new ValueWriter<IndicatorValue>()));
    AddBinding(m_IndustrialProfitability = new GetterValueBinding<IndicatorValue>(
        "companyInfoview", "industrialProfitability", GetIndustrialProfitability, new ValueWriter<IndicatorValue>()));
    AddBinding(m_OfficeProfitability = new GetterValueBinding<IndicatorValue>(
        "companyInfoview", "officeProfitability", GetOfficeProfitability, new ValueWriter<IndicatorValue>()));
}