Game.UI.InGame.DescriptionSection
Assembly:
Assembly-CSharp (Assembly-CSharp.dll)
Namespace:
Game.UI.InGame
Type:
class
Base:
InfoSectionBase
Summary:
DescriptionSection is a UI info section used in the in-game inspector to show a prefab/entity description and aggregated effect data (local modifiers, city modifiers, leisure providers). It collects modifier data from the selected prefab and from installed upgrades on the selected entity, prepares those lists for the prefab UI binders, and writes them out via IJsonWriter for the UI. It uses Unity.Entities and Unity.Collections NativeList buffers and is responsible for allocating and disposing persistent NativeLists used during the object's lifetime. It also controls its own visibility based on the selected entity/prefab components (e.g., routes, districts, service objects, outside connections, upgrades).
Fields
-
private PrefabUISystem m_PrefabUISystem
{{ This holds a reference to the PrefabUISystem (retrieved from the World in OnCreate). It is used to obtain title/description IDs and to provide access to the binder helpers for writing modifier/leisure data. }} -
private NativeList<LeisureProviderData> m_LeisureDatas
{{ Persistent NativeList used to collect LeisureProviderData from the selected prefab and from installed upgrades. Initialized with capacity 10 in OnCreate and disposed in OnDestroy. Used by the leisure binder when writing UI data. }} -
private NativeList<LocalModifierData> m_LocalModifierDatas
{{ Persistent NativeList used to collect local modifier data from the selected prefab and from installed upgrades. Initialized with capacity 10 in OnCreate and disposed in OnDestroy. Sent to the local modifier binder for UI output. }} -
private NativeList<CityModifierData> m_CityModifierDatas
{{ Persistent NativeList used to collect city modifier data from the selected prefab and from installed upgrades. Initialized with capacity 10 in OnCreate and disposed in OnDestroy. Sent to the city modifier binder for UI output. }}
Properties
-
protected override string group => "DescriptionSection"
{{ The UI group identifier used by the base InfoSectionBase to categorize or identify this section in the UI system. }} -
private string localeId { get; set; }
{{ Holds the locale string identifier for the description text retrieved from the PrefabUISystem for the selected prefab. Written to JSON as "localeId" by OnWriteProperties. }} -
protected override bool displayForOutsideConnections => true
{{ Controls whether the section should be displayed for outside connection entities. }} -
protected override bool displayForUnderConstruction => true
{{ Controls whether the section should be displayed for entities that are under construction. }} -
protected override bool displayForUpgrades => true
{{ Controls whether the section should be displayed when the entity has upgrades. }}
Constructors
public DescriptionSection()
{{ Parameterless public constructor. The object-level initialization of NativeLists and system references happens in the overridden OnCreate method rather than the ctor. }}
Methods
-
[Preserve] protected override void OnCreate()
{{ Called when the section is created by the ECS/UI system. Calls base.OnCreate(), obtains the PrefabUISystem from the World, and allocates three persistent NativeList instances (m_LeisureDatas, m_LocalModifierDatas, m_CityModifierDatas) with an initial capacity of 10. }} -
[Preserve] protected override void OnDestroy()
{{ Called when the section is destroyed. Disposes the three NativeList instances to avoid memory leaks, then calls base.OnDestroy(). Important because the lists are Allocator.Persistent. }} -
protected override void Reset()
{{ Clears the three NativeLists and resets localeId to null. Used to clear transient state when the section is reset between selections. }} -
private bool Visible()
{{ Internal visibility check used by OnUpdate to set base.visible. Determines if the section should be visible based on the selected entity/prefab component composition (checks for Route, District+Area, ServiceObjectData, SignatureBuildingData, OutsideConnection, and ServiceUpgrade). The logic ensures correct visibility for a variety of prefab/entity types and upgrades. }} -
[Preserve] protected override void OnUpdate()
{{ Called each update tick; sets base.visible by evaluating Visible(). This drives whether the UI section is shown. }} -
protected override void OnProcess()
{{ Main processing routine that runs when the section is active. It: - Retrieves title/description IDs from PrefabUISystem and stores description locale ID in localeId.
- Attempts to read LocalModifierData and CityModifierData buffers from the selected prefab and appends them to the corresponding NativeLists.
- Checks for a LeisureProviderData component on the prefab and adds it to the leisure list if its efficiency > 0.
-
Iterates installed upgrades on the selected entity (InstalledUpgrade buffer), and for each upgrade that references a PrefabRef, it reads the upgrade prefab's LocalModifierData/CityModifierData/LeisureProviderData and adds them to the temporary lists (using LocalEffectSystem / CityModifierUpdateSystem / LeisureSystem helper methods where applicable). This aggregates base prefab effects + upgrade effects so the UI shows the effective modifiers. }}
-
public override void OnWriteProperties(IJsonWriter writer)
{{ Writes the collected data to an IJsonWriter used by the UI layer. It writes: - "localeId": the stored locale id string
- "effects": an array containing 0..3 elements (city modifiers, local modifiers, leisure providers) depending on whether the respective lists contain items. The method uses PrefabUISystem's binders (CityModifierBinder, LocalModifierBinder, LeisureProviderBinder) to serialize the NativeList contents into JSON. Before calling this, processing should have populated the NativeLists. }}
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_PrefabUISystem = base.World.GetOrCreateSystemManaged<PrefabUISystem>();
m_LeisureDatas = new NativeList<LeisureProviderData>(10, Allocator.Persistent);
m_LocalModifierDatas = new NativeList<LocalModifierData>(10, Allocator.Persistent);
m_CityModifierDatas = new NativeList<CityModifierData>(10, Allocator.Persistent);
}
{{ Notes and tips for modders: - Because the NativeLists use Allocator.Persistent, always ensure OnDestroy disposes them to prevent leaks. - The class aggregates data from both prefab definitions and installed upgrades; if you create custom upgrade prefabs, supply LocalModifierData / CityModifierData / LeisureProviderData buffers/components on the upgrade prefabs so they are included in this UI section. - The PrefabUISystem binders expect NativeList data in the same types; if you modify or extend those data structures, update the binders accordingly. - Visibility logic is tailored to many prefab/entity types; if you add new entity/component types that should change visibility, update the Visible() method accordingly. }}