Game.Prefabs.InfoviewInitializeSystem
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: GameSystemBase
Summary:
InfoviewInitializeSystem is a GameSystem that prepares and assigns infoview (information view / heatmap / status) modes to placeable prefabs. It builds mappings between Infomode groups and Infoview prefabs, computes scores for available infomodes against placeable objects (zones, buildings, roads, pipelines, etc.), and populates each placeable prefab's PlaceableInfoviewItem buffer with the best matching infoview and any supplemental modes. Work is performed using Unity ECS jobs (burst-compatible) to run efficiently on chunks: FindInfoviewJob, FindSubInfoviewJob and AssignInfoviewJob. The system also exposes enumerable accessors to all registered Infoview and Infomode prefabs.
Fields
-
private EntityQuery m_NewInfoviewQuery
Tracks newly created infoview prefab entities (PrefabData + InfoviewData + Created) so the system can initialize their InfoviewMode buffers. -
private EntityQuery m_AllInfoviewQuery
Query matching all infoview prefabs (PrefabData + InfoviewData). Used when finding best infoviews for placeable objects. -
private EntityQuery m_AllInfomodeQuery
Query matching all infomode prefabs (PrefabData + InfomodeData, excluding InfomodeGroup). Used to compute scores for specific infomode entities. -
private EntityQuery m_NewPlaceableQuery
Query matching newly created placeable prefabs with PlaceableInfoviewItem buffer (PrefabData + PlaceableInfoviewItem + Created) so their assigned infoviews can be computed. -
private EntityQuery m_AllPlaceableQuery
Query matching all placeable prefabs that have PlaceableInfoviewItem buffers. Used to populate the buffers with selected infoview(s). -
private PrefabSystem m_PrefabSystem
Reference to the PrefabSystem (managed) used to resolve PrefabData -> typed prefab classes and to map mode/prefab references to Entities. -
private ResourceSystem m_ResourceSystem
Reference to the ResourceSystem (managed) used when checking resource-related subareas and extractor/prefab requirements. -
private TypeHandle __TypeHandle
Internal struct containing Component/Buffer/Entity type handles used to create and schedule job data. Populated during OnCreateForCompiler. -
private const int TYPE_PRIORITY = 1000000
Priority constant used when computing scores (present as literal constants in the class). -
private const int PRIMARY_REQUIREMENT_PRIORITY = 10000
Priority constant used for primary requirements/effects. -
private const int SECONDARY_REQUIREMENT_PRIORITY = 10000
Priority constant used for secondary requirements. -
private const int PRIMARY_EFFECT_PRIORITY = 10000
Priority constant used for primary effects. -
private const int SECONDARY_EFFECT_PRIORITY = 100
Priority constant used for secondary effects.
Properties
-
public IEnumerable<InfoviewPrefab> infoviews { get; }
Returns an enumerable over all registered Infoview prefabs. Iterates the m_AllInfoviewQuery chunks, resolves each PrefabData with PrefabSystem.GetPrefab(). Useful for inspecting or iterating over available infoview types in managed code. -
public IEnumerable<InfomodePrefab> infomodes { get; }
Returns an enumerable over all registered Infomode prefabs. Iterates the m_AllInfomodeQuery chunks and resolves each PrefabData with PrefabSystem.GetPrefab(). Useful for mods that need to examine or extend available modes.
Constructors
public InfoviewInitializeSystem()
Default constructor. The system initializes its queries and type handles in OnCreate / OnCreateForCompiler. The constructor itself does not perform heavy setup.
Methods
protected override void OnCreate()
Called when the system is created. It acquires references to PrefabSystem and ResourceSystem and sets up EntityQueries:- m_NewInfoviewQuery: PrefabData + InfoviewData + Created
- m_AllInfoviewQuery: PrefabData + InfoviewData
- m_AllInfomodeQuery: PrefabData + InfomodeData (exclude InfomodeGroup)
- m_NewPlaceableQuery: PrefabData + PlaceableInfoviewItem + Created
- m_AllPlaceableQuery: PrefabData + PlaceableInfoviewItem
These queries are later used to initialize infoview mode lists and to compute assignments.
protected override void OnUpdate()
Main update loop. If there are newly created infoview prefabs, it:- Calls InitializeInfoviews(...) to populate InfoviewMode buffers for infoview prefabs (combines infomode groups into the infoview).
-
Calls FindInfoviews(...) to compute and assign best infoview(s) to placeable prefabs. If there are newly created placeable prefabs but no new infoviews, it schedules FindInfoviews for just the new placeables.
-
private JobHandle InitializeInfoviews(JobHandle inputDeps, EntityQuery infoviewGroup, EntityQuery infomodeGroup)
Synchronous part (job dependencies Completed before CPU work) that: - Builds a NativeParallelMultiHashMap mapping InfomodeGroup entity -> member infomode entities and priorities (InfoModeData).
- Iterates all infoview prefabs and, for each InfomodeInfo entry on the Infoview prefab, expands group memberships into concrete InfoviewMode entries added to the Infoview prefab's InfoviewMode buffer.
- Computes combined priorities as: infomodeInfo.m_Priority * 1_000_000 + infomodeInfo.m_Mode.m_Priority * 1000 + groupPriority (if from group).
- Uses PrefabSystem to resolve prefabs and entities.
This method returns a JobHandle (no follow-up job currently scheduled from it inside the method body).
private JobHandle FindInfoviews(JobHandle inputDeps, EntityQuery infoviewQuery, EntityQuery infomodeQuery, EntityQuery objectQuery)
Main work pipeline to select best infoviews for placeable objects. Sets up:- NativeQueue
to pass assignment pairs from sub-search job into assign job. - Creates two chunk lists for infoviews and infomodes (async).
- Schedules FindInfoviewJob as a parallel JobChunk across objectQuery (the placeable objects or the new placeables depending).
- FindInfoviewJob inspects chunk component signatures (lots of component type handles for buildings, zones, pipelines, etc.), computes a searchData bitmask/priority structure per-object and calculates scores per infomode entity using CalculateInfomodeScores. It then finds the best Infoview (via GetBestInfoView) and writes PlaceableInfoviewItem entries into the placeable's buffer.
- Schedules FindSubInfoviewJob to check for placeables that should inherit an infoview from a sub-prefab or zone/lot subarea; enqueues assignment pairs into the NativeQueue.
- Schedules AssignInfoviewJob which dequeues pairs and copies the placeable infoview buffers from source to target.
-
Disposes native containers with proper dependencies and returns a combined JobHandle.
-
Nested/Burst jobs:
-
FindInfoviewJob : IJobChunk
Complex job that:- Builds an InfoviewSearchData struct capturing what to search for (service coverage, building types, net types, zone types, pollution/water types, priorities, etc.).
- For each object in an archetype chunk it populates searchData based on chunk components and buffer contents, then:
- Calls CalculateInfomodeScores() to evaluate every infomode entity across m_InfomodeChunks and fill a NativeParallelHashMap
of scores. - Calls GetBestInfoView() which iterates m_InfoviewChunks' InfoviewMode buffers to compute combined scores for Infoview prefabs and choose the best one (and supplemental modes).
- Fills the placeable object's PlaceableInfoviewItem buffer with the best results.
- Calls CalculateInfomodeScores() to evaluate every infomode entity across m_InfomodeChunks and fill a NativeParallelHashMap
- Helper static mapping functions included: GetMapFeature, GetTerraformingTarget, GetMaintenanceType, GetPollutionType, GetWaterType.
-
FindSubInfoviewJob : IJobChunk
Examines spawnable-building/subarea/upgrade buffers to determine if a placeable should instead use an infoview from a referenced zone/sub-prefab. Enqueues InfoviewBufferData entries when assignments must be copied from a source prefab to a target. -
AssignInfoviewJob : IJob
Consumes the NativeQueue of InfoviewBufferData and copies the PlaceableInfoviewItem buffer from the source entity to the target entity. -
Utility helpers inside FindInfoviewJob:
- CalculateInfomodeScores(InfoviewSearchData, NativeParallelHashMap
)
Iterates infomode chunks and, based on the searchData flags and priorities, scores infomode Entities by their component data (InfoviewBuildingData, InfoviewVehicleData, InfoviewHeatmapData, InfoviewCoverageData, etc.). Uses AddInfomodeScore to keep the maximum score per infomode entity. -
GetBestInfoView(InfoviewSearchData, NativeParallelHashMap
, NativeList supplementalModes, out int bestScore)
Iterates infoviewChunks and their InfoviewMode buffers. For each infoview prefab (entity) it sums the scores of included infomodes, applying supplemental/optional rules, keeps the best-scoring Infoview, and gathers any supplemental modes to return with the best result. -
protected override void OnCreateForCompiler()
Internal helper used by the compiled system to assign type handles and queries at construction-time via __AssignQueries and __TypeHandle.__AssignHandles. -
Static mapping functions (public in the job struct):
public static MapFeature GetMapFeature(HeatmapData heatmapType)
public static TerraformingTarget GetTerraformingTarget(HeatmapData heatmapType)
public static MapFeature GetMapFeature(ObjectStatusType statusType)
public static MaintenanceType GetMaintenanceType(BuildingType buildingType)
public static PollutionType GetPollutionType(HeatmapData heatmapType)
public static WaterType GetWaterType(HeatmapData heatmapType)
These map heatmap/object/status enums to the system's internal filter enums used when scoring modes.
Usage Example
// Example: Iterate all registered infoview prefabs from another managed system or mod hook
var world = World.DefaultGameObjectInjectionWorld; // or use the game's world reference
var infoviewSystem = world.GetExistingSystemManaged<Game.Prefabs.InfoviewInitializeSystem>();
if (infoviewSystem != null)
{
foreach (var ivPrefab in infoviewSystem.infoviews)
{
// inspect ivPrefab, log name or adjust mod behaviour
Debug.Log($"Infoview prefab: {ivPrefab.name}");
}
foreach (var imPrefab in infoviewSystem.infomodes)
{
Debug.Log($"Infomode prefab: {imPrefab.name}");
}
}
Notes and tips: - This system relies heavily on ECS buffers and prefab components (InfoviewMode, PlaceableInfoviewItem, InfoviewBuildingData, etc.). When authoring new Infoview/Infomode prefabs, ensure correct component types and priorities are configured on the prefab assets so they participate in scoring. - Priority encoding: Infoview selection composes priorities using multiples (mode group priority, mode priority, infomode priority) so designers can express coarse vs. fine-grained weighting. - The heavy computation runs inside burst-compiled jobs; keep any custom additions to component data and job-compatible types to maintain performance. - If you add new heatmap/object types, update the mapping helper functions (GetMapFeature/GetPollutionType/GetWaterType/GetTerraformingTarget) so they are considered during scoring.