Skip to content

Game.UI.InGame.LandValueInfoviewUISystem

Assembly:
Assembly-CSharp (game runtime assembly where UI systems live; actual assembly name may vary by build)

Namespace:
Game.UI.InGame

Type:
class LandValueInfoviewUISystem

Base:
InfoviewUISystemBase

Summary:
This UI system computes and exposes the average land value for the in-game land-value infoview. It queries Building entities (excluding Deleted and Temp) and, via a Burst-compiled IJobChunk, sums land values looked up from a LandValue component associated with each building's road edge. The result is published through a ValueBinding ("landValueInfo", "averageLandValue") for consumption by the UI. The system uses a persistent NativeArray of length 2 to accumulate sum and count, and disposes it on destruction.


Fields

  • private const string kGroup = "landValueInfo"
    Identifier/group name used for the ValueBinding; groups the data exposed to the UI.

  • private ValueBinding<float> m_AverageLandValue
    Binding instance that publishes the computed average land value to the UI under the group/key ("landValueInfo", "averageLandValue"). Updated each frame in UpdateLandValue.

  • private EntityQuery m_LandValueQuery
    ECS query used to select Building entities that should be considered when computing the average land value. The query requires Building and BuildingCondition, and excludes Deleted and Temp.

  • private NativeArray<float> m_Results
    Persistent NativeArray of length 2 used as a simple accumulator: index 0 accumulates the sum of land values, index 1 accumulates the count of valid buildings. Allocated with Allocator.Persistent in OnCreate and disposed in OnDestroy.

  • private TypeHandle __TypeHandle
    Generated container holding ComponentTypeHandle/ComponentLookup instances (for Building and LandValue) used by the job. Populated via __AssignHandles in OnCreateForCompiler to access ECS components safely.

  • private struct CalculateAverageLandValueJob (nested)
    Burst-compiled IJobChunk that iterates chunks of Building components and uses the ComponentLookup to read LandValue for each Building's road edge. It updates m_Results[0] (sum) and m_Results[1] (count).

Properties

  • protected override bool Active { get; }
    The system's Active property is overridden to take the UI binding into account: if the base system is not active, this checks m_AverageLandValue.active and returns true if the binding itself is active. This makes the system run (active) when the UI requests it.

Constructors

  • public LandValueInfoviewUISystem()
    Default constructor. The system relies on OnCreate/OnCreateForCompiler for initialization; constructor is preserved for runtime creation by the ECS/system loader.

Methods

  • protected override void OnCreate()
    Initializes the EntityQuery (selects Building + BuildingCondition and excludes Deleted/Temp), creates and registers the ValueBinding (key "landValueInfo"/"averageLandValue" with initial value 0f), and allocates m_Results (NativeArray(2, Allocator.Persistent)). Called when the system is created.

  • protected override void OnDestroy()
    Cleans up managed and unmanaged state. Calls base.OnDestroy() and disposes of m_Results to avoid memory leaks.

  • protected override void PerformUpdate()
    Called by the base system to perform per-frame updates; delegates work to UpdateLandValue().

  • private void UpdateLandValue()
    Resets the accumulator m_Results to zeros, schedules the Burst IJobChunk CalculateAverageLandValueJob (populating component handles/lookups via InternalCompilerInterface and the stored TypeHandle), waits for the job to complete, computes the average as (sum / count) if count > 0 else 0, and updates m_AverageLandValue with the computed value. Uses base.Dependency when scheduling.

  • private void __AssignQueries(ref SystemState state)
    Compiler-injected helper that would normally assign EntityQuery instances. In this build it contains a no-op stub (new EntityQueryBuilder(Allocator.Temp).Dispose()) — present for IL/IL2CPP/compiled-system compatibility.

  • protected override void OnCreateForCompiler()
    Compiler-time initialization helper: invokes base.OnCreateForCompiler(), __AssignQueries and __TypeHandle.__AssignHandles to prepare the component handles/lookups used by the job. This is part of the generated system pattern for ECS compatibility.

  • private struct TypeHandle.__AssignHandles(ref SystemState state)
    Assigns __Game_Buildings_Building_RO_ComponentTypeHandle via state.GetComponentTypeHandle(isReadOnly: true) and __Game_Net_LandValue_RO_ComponentLookup via state.GetComponentLookup(isReadOnly: true). Ensures the job has the correct handles/lookups for execution.

  • private struct CalculateAverageLandValueJob.Execute(...)
    Job execution method: iterates the Building component array in the chunk, for each Building looks up a LandValue via building.m_RoadEdge, and if present accumulates land value and increments count in the shared m_Results array. Implemented with BurstCompile for performance.

Notes on safety and lifecycle: - m_Results is Allocator.Persistent and must be disposed (done in OnDestroy). - The job writes to a NativeArray passed by reference. Because Schedule(...).Complete() is called immediately, there are no race conditions in the example, but if you were to schedule without immediate completion you'd need proper synchronization. - Component handles/lookups are obtained through InternalCompilerInterface helper calls (to work with the generated TypeHandle and CheckedStateRef used in compiled ECS systems).

Usage Example

// The system already registers its binding and handles lifecycle internally.
// Example snippet showing the essential parts (similar to the system's OnCreate):

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

    // Query buildings (requires Building + BuildingCondition, exclude Deleted/Temp)
    m_LandValueQuery = GetEntityQuery(
        ComponentType.ReadOnly<Building>(),
        ComponentType.ReadOnly<BuildingCondition>(),
        ComponentType.Exclude<Deleted>(),
        ComponentType.Exclude<Temp>());

    // Register a UI binding (group "landValueInfo", key "averageLandValue")
    AddBinding(m_AverageLandValue = new ValueBinding<float>("landValueInfo", "averageLandValue", 0f));

    // Allocate accumulator: [0] = sum, [1] = count
    m_Results = new NativeArray<float>(2, Allocator.Persistent);
}

// OnDestroy must dispose the NativeArray:
[Preserve]
protected override void OnDestroy()
{
    base.OnDestroy();
    m_Results.Dispose();
}

If you need to read the published value from UI code, subscribe or query the ValueBinding under group "landValueInfo" and key "averageLandValue" (depending on your UI binding API).