Game.UI.InGame.AttractivenessSection
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: class
Base: InfoSectionBase
Summary:
AttractivenessSection is an in-game UI info section that computes and exposes the "attractiveness" value of the selected building/object (base value plus modifiers). It queries AttractionData/AttractivenessProvider data, applies building efficiency and park maintenance modifiers, evaluates terrain-based attractiveness via TerrainAttractivenessSystem/TerrainSystem, collects individual attractiveness factors, and serializes those values for UI/JSON output. It contains a small nested value type AttractivenessFactor used to store and serialize each factor (locale key + delta) and to allow sorting.
Fields
-
private TerrainAttractivenessSystem m_TerrainAttractivenessSystem
Used to read terrain-based attractiveness data (fetched from the ECS world in OnCreate). -
private TerrainSystem m_TerrainSystem
Used to obtain terrain height data when evaluating terrain attractiveness. -
private EntityQuery m_SettingsQuery
EntityQuery for AttractivenessParameterData singleton, used to obtain settings for terrain attractiveness evaluation. -
protected override string group => "AttractivenessSection"
Override of the InfoSectionBase.group property; identifies the section's group name for the UI. -
private float baseAttractiveness { get; set; }
Stores the base attractiveness value taken from AttractionData (before modifiers). -
private float attractiveness { get; set; }
Final attractiveness value after applying all modifiers. -
private List<AttractivenessFactor> factors { get; set; }
List of computed attractiveness factors (instances of the nested AttractivenessFactor) that contributed non-zero deltas.
Nested type (value object) — not a field but important to mention:
- private readonly struct AttractivenessFactor : IJsonWritable, IComparable<AttractivenessFactor>
Contains:
- private int localeKey
— integer index corresponding to AttractionSystem.AttractivenessFactor enum (used to identify factor type / locale string).
- private float delta
— the percentage delta contributed by this factor.
- Implements Write(IJsonWriter) to serialize as { localeKey:
Properties
-
public
(implicit via base)group
(protected override)
Group identifier used by the section ("AttractivenessSection"). -
private float baseAttractiveness { get; set; }
Base attractiveness value read from AttractionData (see Fields). -
private float attractiveness { get; set; }
Final computed attractiveness after modifiers (see Fields). -
private List<AttractivenessFactor> factors { get; set; }
Collected list of non-zero factors (see Fields).
Constructors
public AttractivenessSection()
Default constructor. Marked with [Preserve] on the type/methods; no special runtime initialization is performed here — initialization of systems and collections takes place in OnCreate.
Methods
-
protected override void Reset()
Resets the internal state between selections/updates: sets baseAttractiveness to 0 and clears the factors list. -
[Preserve] protected override void OnCreate()
Initializes runtime-only members: - Allocates the factors List (capacity 5).
- Obtains references to TerrainAttractivenessSystem and TerrainSystem via World.GetOrCreateSystemManaged.
-
Builds an EntityQuery for AttractivenessParameterData (m_SettingsQuery). Call base.OnCreate() as well.
-
private bool Visible()
Determines whether this info section should be visible for the current selection: - Returns true if the selected prefab/entity has AttractionData, or if the selected entity has an AttractivenessProvider component.
-
Used by OnUpdate to set base.visible.
-
[Preserve] protected override void OnUpdate()
Sets base.visible according to Visible() each frame/update. -
protected override void OnProcess()
Core computation routine that: - Allocates a temporary NativeArray
(5) to collect factor deltas (each index corresponds to an AttractionSystem.AttractivenessFactor). - Reads AttractionData (with upgrades) for the selected prefab/entity to get baseAttractiveness.
- Applies building efficiency (reads DynamicBuffer
and uses BuildingUtils.GetEfficiency), modifies attractiveness and writes the Efficiency factor to the native array. - If the entity is a Park (Game.Buildings.Park) and ParkData is available, computes a maintenance multiplier from component.m_Maintenance and data2.m_MaintenancePool, applies it to attractiveness, and sets the Maintenance factor in the native array.
- If the entity has a Game.Objects.Transform, fetches terrain attractiveness data (retrieving a CellMapData
and appropriate JobHandle dependency), completes dependencies, gets TerrainHeightData from TerrainSystem, gets AttractivenessParameterData from the settings query, evaluates terrain attractiveness via TerrainAttractivenessSystem.EvaluateAttractiveness and applies the result to attractiveness; TerrainAttractivenessSystem writes factors into the nativeArray as well. - Iterates the nativeArray and for any non-zero entry, constructs and adds an AttractivenessFactor(index, delta) to factors.
- Disposes the nativeArray when done.
-
Job dependencies are combined into base.Dependency where appropriate.
-
public override void OnWriteProperties(IJsonWriter writer)
Serializes the computed data for UI/JSON: - Writes "attractiveness" (final value).
- Writes "baseAttractiveness".
- Writes "factors" as an array of AttractivenessFactor objects (they implement IJsonWritable and write localeKey as the enum name plus delta).
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// allocate list and grab required systems/queries
factors = new List<AttractivenessFactor>(5);
m_TerrainAttractivenessSystem = base.World.GetOrCreateSystemManaged<TerrainAttractivenessSystem>();
m_TerrainSystem = base.World.GetOrCreateSystemManaged<TerrainSystem>();
m_SettingsQuery = GetEntityQuery(ComponentType.ReadOnly<AttractivenessParameterData>());
}
Notes and implementation tips:
- The class depends on ECS components/types: AttractionData, AttractivenessProvider, AttractivenessParameterData, Efficiency buffers, Park/ ParkData, Game.Objects.Transform, TerrainAttractivenessSystem, and TerrainSystem.
- The NativeArray