Game.UI.InGame.NaturalResourcesInfoviewUISystem
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: class
Base: InfoviewUISystemBase
Summary:
NaturalResourcesInfoviewUISystem is a UI system that collects and aggregates natural resource data (fertility, forest, oil, ore, fish) from map tiles and extractor buildings and exposes those values to the in-game infoview via ValueBinding
Fields
-
private enum Result
A private enum used as named indices into the m_Results NativeArray. Entries include FertilityAmount, ForestAmount, OilAmount, OreAmount, FishAmount, FertilityExtraction, ForestExtraction, OilExtraction, OreExtraction, FertilityRenewal, ForestRenewal, FishExtraction, FishRenewal, Count. This provides readable indices when reading/writing to m_Results. -
private struct UpdateResourcesJob
Burst-compiled IJobChunk that reads MapFeatureElement buffers on MapTile entities and aggregates available amounts and renewal rates into the provided NativeArraym_Results. It sums amounts/renewalRates for features (fertility, forest, oil, ore, fish). -
private struct UpdateExtractionJob
Burst-compiled IJobChunk that iterates extractor-related entities (extractor companies / extractor buildings) to compute daily extraction (production) for each resource type. It reads many component lookups (PrefabRef, Attached, ExtractorAreaData, efficiency buffers, installed upgrades, industrial process/workplace data, resource data) and accumulates extraction amounts into m_Result. -
private struct TypeHandle
A utility struct that stores Type/Buffer/Component lookup handles used to access entity data in jobs. It includes an __AssignHandles(ref SystemState) method to initialize the handles from a SystemState. -
private const string kGroup
Constant string "naturalResourceInfo". Used as the binding group name. -
private ResourceSystem m_ResourceSystem
Reference to the ResourceSystem instance from the world. Used to access resource prefabs and related systems. -
private ValueBinding<float> m_AvailableOil
Binding exposed to the UI for total available oil. -
private ValueBinding<float> m_AvailableOre
Binding exposed to the UI for total available ore. -
private ValueBinding<float> m_AvailableForest
Binding exposed to the UI for total available forest. -
private ValueBinding<float> m_AvailableFertility
Binding exposed to the UI for total available fertility. -
private ValueBinding<float> m_ForestRenewalRate
Binding exposed to the UI for forest renewal rate. -
private ValueBinding<float> m_FertilityRenewalRate
Binding exposed to the UI for fertility renewal rate. -
private ValueBinding<float> m_FishRenewalRate
Binding exposed to the UI for fish renewal rate. -
private ValueBinding<float> m_AvailableFish
Binding exposed to the UI for total available fish. -
private ValueBinding<float> m_OilExtractionRate
Binding exposed to the UI for oil extraction/production rate. -
private ValueBinding<float> m_OreExtractionRate
Binding exposed to the UI for ore extraction/production rate. -
private ValueBinding<float> m_ForestExtractionRate
Binding exposed to the UI for forest extraction/production rate. -
private ValueBinding<float> m_FertilityExtractionRate
Binding exposed to the UI for fertility (soil) extraction/production rate. -
private ValueBinding<float> m_FishExtractionRate
Binding exposed to the UI for fish extraction/production rate. -
private EntityQuery m_MapTileQuery
EntityQuery selecting MapTile entities that have MapFeatureElement buffers (and are not Native). Used to schedule UpdateResourcesJob. -
private EntityQuery m_ExtractorQuery
EntityQuery selecting extractor company / extractor building entities (PropertyRenter, WorkProvider, PrefabRef, excluding Deleted and Temp). Used to schedule UpdateExtractionJob. -
private NativeArray<float> m_Results
NativeArraylength 13 used to accumulate results from jobs. Indices map to the Result enum. Persistently allocated (Allocator.Persistent) and disposed on OnDestroy. -
private TypeHandle __TypeHandle
Instance of the TypeHandle struct holding the Job/Component handles for this system. -
private EntityQuery __query_1701516005_0
Generated EntityQuery that selects the EconomyParameterData singleton (with IncludeSystems option). Used to retrieve economy parameters required by the extraction job.
Properties
-
public override GameMode gameMode { get; }
Returns GameMode.GameOrEditor. Indicates this system runs in both normal gameplay and editor mode. -
protected override bool Active { get; }
Determines if the infoview system should be active. Returns true if base.Active is true or any of the ValueBinding controls (available/fertility/forest/oil/ore bindings and extraction rate bindings) are active — otherwise false. Controls whether updates are performed for performance.
Constructors
public NaturalResourcesInfoviewUISystem()
Default constructor (marked [Preserve] on lifecycle methods). Initialization logic primarily happens in OnCreate.
Methods
-
[Preserve] protected override void OnCreate()
Initializes the system: gets the ResourceSystem from the world, sets up all ValueBindinginstances (group "naturalResourceInfo" with keys like "availableOil"), creates entity queries (m_MapTileQuery, m_ExtractorQuery), allocates m_Results NativeArray (13 floats, Persistent), and declares required component singletons for update (ExtractorParameterData, EconomyParameterData). Called when the system is created. -
[Preserve] protected override void OnDestroy()
Disposes m_Results NativeArray and calls base.OnDestroy. Ensures persistent native allocation is freed. -
protected override void PerformUpdate()
Main update: resets m_Results, schedules and completes UpdateResourcesJob (scanning map tile feature buffers) and UpdateExtractionJob (scanning extractor buildings), then updates all ValueBindingtargets with aggregated amounts and rates from m_Results. Uses InternalCompilerInterface to get job handles/lookups from __TypeHandle and reads EconomyParameterData singleton for economy-based production calculations. -
private void __AssignQueries(ref SystemState state)
Helper called to build the internal query __query_1701516005_0 that selects EconomyParameterData with IncludeSystems option. Called from OnCreateForCompiler. -
protected override void OnCreateForCompiler()
Compiler helper used by codegen: assigns queries and type handles by calling __AssignQueries and __TypeHandle.__AssignHandles with the system state. Ensures the TypeHandle and queries are ready for job scheduling. -
Nested job methods (UpdateResourcesJob.Execute / UpdateExtractionJob.Execute and ProcessAreas)
Implementation details inside the nested jobs: UpdateResourcesJob reads MapFeatureElement buffers and adds amounts/renewal to m_Results; UpdateExtractionJob computes production per extractor building (taking efficiency, workers, level, resources in extractor area, installed upgrades, and economy parameters into account) and accumulates resource extraction totals.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Initialize resource system and bindings (example excerpt)
m_ResourceSystem = base.World.GetOrCreateSystemManaged<ResourceSystem>();
AddBinding(m_AvailableOil = new ValueBinding<float>("naturalResourceInfo", "availableOil", 0f));
AddBinding(m_AvailableOre = new ValueBinding<float>("naturalResourceInfo", "availableOre", 0f));
AddBinding(m_AvailableForest = new ValueBinding<float>("naturalResourceInfo", "availableForest", 0f));
AddBinding(m_AvailableFertility = new ValueBinding<float>("naturalResourceInfo", "availableFertility", 0f));
// Setup queries and persistent results array
m_MapTileQuery = GetEntityQuery(ComponentType.ReadOnly<MapTile>(), ComponentType.ReadOnly<MapFeatureElement>(), ComponentType.Exclude<Native>());
m_ExtractorQuery = GetEntityQuery(ComponentType.ReadOnly<Game.Companies.ExtractorCompany>(),
ComponentType.ReadOnly<PropertyRenter>(),
ComponentType.ReadOnly<WorkProvider>(),
ComponentType.ReadOnly<PrefabRef>(),
ComponentType.Exclude<Deleted>(),
ComponentType.Exclude<Temp>());
m_Results = new NativeArray<float>(13, Allocator.Persistent);
// Ensure required singletons exist for updates
RequireForUpdate<ExtractorParameterData>();
RequireForUpdate<EconomyParameterData>();
}
Notes and implementation hints: - m_Results indices correspond to the private Result enum; use that mapping when reading/writing values. - The system relies on many component lookups (prefab data, area buffers, installed upgrades, building efficiencies). When extending or reusing, ensure those components exist and are registered. - Jobs are Burst-compiled and scheduled via JobChunkExtensions.Schedule then completed synchronously in PerformUpdate; consider job dependencies if integrating into a larger system pipeline.