Game.UI.InGame.UpgradePropertiesSection
Assembly:
Assembly-CSharp (game code / modding assemblies may compile into Assembly-CSharp)
Namespace:
Game.UI.InGame
Type:
class
Base:
InfoSectionBase
Summary:
UpgradePropertiesSection is a UI info-section used by the in-game UI to show properties related to building upgrades (sub-buildings and extensions). It inspects the currently selected prefab/entity and, when that prefab represents an upgrade (contains ServiceUpgradeData), it exposes the main building entity that the upgrade belongs to, the upgrade entity itself, and whether the upgrade is a SubBuilding or an Extension. The section writes those values into a JSON writer (via OnWriteProperties), typically for the UI/inspector layer to consume.
Fields
private static readonly string kMainBuildingName = "mainBuildingName"
This constant key is used when writing the main building's bound name into the JSON output (writer.PropertyName(kMainBuildingName)).
Nested Types
private enum UpgradeType
- SubBuilding
- Extension
Represents whether the selected upgrade prefab is a sub-building (attached building) or a building extension.
Properties
-
protected override string group => "UpgradePropertiesSection"
UI group identifier used by the base InfoSection system to group/identify this section. -
protected override bool displayForUpgrades => true
Signals to the InfoSection framework that this section should be considered for upgrade prefabs. -
private Entity mainBuilding { get; set; }
Holds the Entity id of the owning/main building for the selected upgrade. Set during processing (OnProcess). Defaults to Entity.Null when reset. -
private Entity upgrade { get; set; }
Holds the Entity id of the selected upgrade prefab (the prefab being inspected). -
private UpgradeType type { get; set; }
The resolved UpgradeType for the selected prefab (SubBuilding or Extension).
Constructors
public UpgradePropertiesSection()
Default constructor. Marked with [Preserve] in source to avoid being stripped by Unity's code stripping.
Methods
-
protected override void Reset()
Resets internal tracking fields to their default (sets mainBuilding and upgrade to Entity.Null). Called by the base lifecycle when the section is reset. -
private bool Visible()
Returns true if the currently selected prefab has a ServiceUpgradeData component (i.e., it is an upgrade). Used to determine whether this section should be visible. -
[Preserve] protected override void OnUpdate()
Called during the section update step. Sets base.visible based on Visible(), i.e., shows/hides the section depending on whether the selected prefab is an upgrade. -
protected override void OnProcess()
Populates internal fields based on the selectedEntity/selectedPrefab: - Sets upgrade = selectedPrefab.
- Attempts to get Owner component on selectedEntity to locate the main building (component.m_Owner).
- If the main building has an Attachment component whose m_Attached is not Entity.Null, the attached entity is used as the main building instead.
-
Determines type by checking whether the selectedPrefab has BuildingExtensionData (if so -> Extension, otherwise -> SubBuilding).
-
public override void OnWriteProperties(IJsonWriter writer)
Writes the section's properties into the provided JSON writer. Output fields: - "mainBuilding" — writes the mainBuilding Entity id.
- "mainBuildingName" — binds and writes the human-readable name for mainBuilding via m_NameSystem.BindName(writer, mainBuilding).
- "upgrade" — writes the upgrade Entity id.
- "type" — writes the type as a string ("SubBuilding" or "Extension").
Notes: This method relies on members provided by the base class (such as selectedPrefab, selectedEntity, EntityManager and m_NameSystem). The method is used to serialize the inspected information for UI/inspector code.
Usage Example
The typical usage is internal to the InfoSection system. If you need to extend or add more properties, derive from this section and override OnWriteProperties while calling base to keep the standard fields:
public class MyCustomUpgradeSection : UpgradePropertiesSection
{
public override void OnWriteProperties(IJsonWriter writer)
{
// Keep the standard upgrade properties
base.OnWriteProperties(writer);
// Add custom property
writer.PropertyName("myCustomFlag");
writer.Write(true);
}
}
Alternatively, this section is driven by the InfoSection lifecycle; you can observe that when a prefab/entity representing an upgrade is selected, the section will write these four properties: - mainBuilding (Entity) - mainBuildingName (bound readable name) - upgrade (Entity) - type ("SubBuilding" or "Extension")