Game.UI.InGame.TourismInfoviewUISystem
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: class
Base: InfoviewUISystemBase
Summary:
TourismInfoviewUISystem is an in-game UI system that populates and updates the tourism information infoview. It reads tourism-related data from several game systems (ClimateSystem, CityStatisticsSystem, CitySystem, Tourism system data) and exposes bindings for UI values: attractiveness, tourism rate, average hotel price and weather effect. It uses ECS EntityQuery/JobChunk to aggregate lodging provider data (average hotel price) and tracks modifications to relevant entities to determine when updates are required. NativeArray storage is used for intermediate job results and disposed on destroy.
Fields
-
private ClimateSystem m_ClimateSystem
Holds a reference to the ClimateSystem managed system instance used to compute weather-related effects. -
private CityStatisticsSystem m_CityStatisticsSystem
Reference to CityStatisticsSystem used to fetch tourism statistic values (e.g., tourist count). -
private CitySystem m_CitySystem
Reference to CitySystem used to access city-level components (e.g., the Tourism component on the city entity). -
private ValueBinding<IndicatorValue> m_Attractiveness
A UI binding exposing the city's attractiveness (0–100 indicator value) to the tourism infoview. -
private ValueBinding<int> m_TourismRate
A UI binding that exposes the tourism rate (tourist count/statistic) to the UI. -
private ValueBinding<float> m_AverageHotelPrice
A UI binding that exposes the computed average hotel price (float) to the UI. -
private ValueBinding<float> m_WeatherEffect
A UI binding that exposes the weather effect on attractiveness (percentage) to the UI. -
private EntityQuery m_HotelQuery
EntityQuery selecting lodging provider entities used to compute average hotel price. Excludes Temp and Deleted entities. -
private EntityQuery m_HotelModifiedQuery
EntityQuery that matches lodging provider / property renter entities when they are created/updated/deleted (used to indicate the UI data is modified). -
private NativeArray<int> m_Results
NativeArray of length 2 used as a temporary accumulator for the JobChunk: index 0 accumulates total price, index 1 accumulates count of providers. Allocated with Allocator.Persistent and disposed in OnDestroy. -
private TypeHandle __TypeHandle
Generated container holding ComponentTypeHandlefor job use; assigned in OnCreateForCompiler. -
private EntityQuery __query_1647950437_0
Generated EntityQuery used to get AttractivenessParameterData singleton for computing weather effect.
Properties
-
protected override bool Active
Determines whether the system is active. Returns true if the base system is active or if any of the UI bindings (attractiveness, tourism rate, average hotel price, weather effect) are active. This allows the system to be turned on only when needed by UI subscriptions. -
protected override bool Modified { get; }
Returns whether there are modifications relevant to the hotel data by checking m_HotelModifiedQuery.IsEmptyIgnoreFilter (negated). If any matched entities have been created/updated/deleted, the UI treats the data as modified.
Constructors
public TourismInfoviewUISystem()
Default constructor (preserved). The class primarily performs initialization in OnCreate/OnCreateForCompiler rather than the constructor.
Methods
-
protected override void OnCreate()
Initializes the system: acquires managed system references (ClimateSystem, CityStatisticsSystem, CitySystem), registers UI ValueBindings (attractiveness, tourismRate, averageHotelPrice, weatherEffect), constructs the hotel-related EntityQueries, requests AttractivenessParameterData as a requirement for update, and allocates the NativeArraym_Results (length 2, Persistent allocator). -
protected override void OnDestroy()
Disposes NativeArraym_Results and calls base.OnDestroy to clean up resources. -
protected override void PerformUpdate()
Called each update tick when the system runs. Delegates to: - UpdateAttractiveness()
- UpdateTourismRate()
- UpdateWeatherEffect()
-
UpdateAverageHotelPrice()
-
private void UpdateAttractiveness()
Reads the Tourism component from the city entity via CitySystem and updates m_Attractiveness binding with an IndicatorValue constructed from the component's attractiveness value. -
private void UpdateTourismRate()
Reads tourist count from CityStatisticsSystem (StatisticType.TouristCount) and updates the m_TourismRate binding. -
private void UpdateWeatherEffect()
Computes a weather effect percentage using TourismSystem.GetWeatherEffect with parameters from the AttractivenessParameterData singleton and the ClimateSystem (classification, temperature, precipitation, isRaining, isSnowing). Updates the m_WeatherEffect binding with the computed percentage (scaled to 100f range and negated as in original logic). -
private void UpdateAverageHotelPrice()
Zeroes the m_Results accumulator, schedules a JobChunk (CalculateAverageHotelPriceJob) over m_HotelQuery to sum lodging provider prices and count providers, waits for completion (Complete()), computes the average (total/count) if count > 0, and updates m_AverageHotelPrice binding. Uses InternalCompilerInterface.GetComponentTypeHandle with the generated TypeHandle for LodgingProvider. -
private void __AssignQueries(ref SystemState state)
Generated helper that builds the __query_1647950437_0 EntityQuery to include AttractivenessParameterData and include systems (EntityQueryOptions.IncludeSystems). Called from OnCreateForCompiler to initialize compiler-generated queries. -
protected override void OnCreateForCompiler()
Called by generated code path — calls base.OnCreateForCompiler(), assigns queries (__AssignQueries) and assigns component type handles via __TypeHandle.__AssignHandles.
Nested / Job types (brief)
-
[BurstCompile] private struct CalculateAverageHotelPriceJob : IJobChunk
JobChunk that iterates LodgingProvider components in chunks. It reads LodgingProvider.m_Price; if price > 0 it adds to m_Results[0] and increments m_Results[1]. m_LodgingProviderHandle is read-only, and m_Results is the NativeArrayaccumulator. The job's Execute is invoked by JobChunkExtensions.Schedule and completed on the main thread in UpdateAverageHotelPrice. -
private struct TypeHandle
Holds a ComponentTypeHandle(read-only), with an __AssignHandles(ref SystemState) method to get and store the handle. This is a compiler-generated helper used when scheduling the job.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Acquire systems and register UI bindings (this mirrors what TourismInfoviewUISystem does)
m_ClimateSystem = base.World.GetOrCreateSystemManaged<ClimateSystem>();
m_CityStatisticsSystem = base.World.GetOrCreateSystemManaged<CityStatisticsSystem>();
m_CitySystem = base.World.GetOrCreateSystemManaged<CitySystem>();
AddBinding(m_Attractiveness = new ValueBinding<IndicatorValue>("tourismInfo", "attractiveness", default(IndicatorValue), new ValueWriter<IndicatorValue>()));
AddBinding(m_TourismRate = new ValueBinding<int>("tourismInfo", "tourismRate", 0));
AddBinding(m_AverageHotelPrice = new ValueBinding<float>("tourismInfo", "averageHotelPrice", 0f));
AddBinding(m_WeatherEffect = new ValueBinding<float>("tourismInfo", "weatherEffect", 0f));
// Prepare hotel query and temporary results storage
m_HotelQuery = GetEntityQuery(ComponentType.ReadOnly<PropertyRenter>(),
ComponentType.ReadOnly<LodgingProvider>(),
ComponentType.Exclude<Temp>(),
ComponentType.Exclude<Deleted>());
m_Results = new NativeArray<int>(2, Allocator.Persistent);
}
Notes and modding tips: - The average hotel price aggregation uses a persistent NativeArray shared between main thread and a job; ensure proper disposal in OnDestroy to avoid leaks. - The calculation uses integer accumulation; dividing ints yields integer division — the class converts the accumulator to float when updating the binding (in the source code it's m_Results[0] / num which is integer division; if you need a precise float average consider casting to float before dividing). - The system relies on generated query and type-handle helpers (OnCreateForCompiler, __AssignQueries, __TypeHandle). When porting or modifying, ensure these are kept in sync with ECS API changes. - Weather effect computation uses TourismSystem.GetWeatherEffect and AttractivenessParameterData — ensure that AttractivenessParameterData is present in the world (RequireForUpdate ensures the system will not run otherwise).