Skip to content

Game.UI.InGame.UpgradesSection

Assembly: Assembly-CSharp
Namespace: Game.UI.InGame

Type: class

Base: InfoSectionBase

Summary:
UI section that displays and manages upgrades for the currently selected building/entity. It collects installed upgrades (separating extensions and sub-buildings), exposes UI actions (delete, relocate, focus, toggle Out of Service), and serializes the list of visible upgrades for the selected entity. The section integrates with the game's ToolSystem/ObjectToolSystem, PoliciesUISystem, AudioManager, Prefab/Name systems and uses ECS EntityManager queries and NativeList buffers to gather and present upgrade information.


Fields

  • private ToolSystem m_ToolSystem
    Internal reference to the game's ToolSystem, used to set the active tool when relocating an object.

  • private ObjectToolSystem m_ObjectToolSystem
    Reference to the object-moving tool used to start moving (relocating) an upgrade entity.

  • private UIInitializeSystem m_UIInitializeSystem
    Reference used to access initialization data such as available policies (used to find the "Out of Service" policy).

  • private PoliciesUISystem m_PoliciesUISystem
    Used to apply or toggle the building "Out of Service" policy for a selected entity.

  • private PolicyPrefab m_BuildingOutOfServicePolicy
    Cached PolicyPrefab instance for the "Out of Service" policy discovered during game load.

  • private AudioManager m_AudioManager
    Used to play UI sounds (e.g., bulldoze sound when deleting an upgrade).

  • private EntityQuery m_SoundQuery
    EntityQuery used to read ToolUXSoundSettingsData singleton (to obtain the bulldoze sound).

  • private NativeList<Entity> extensions { get; set; }
    NativeList allocated with Allocator.Persistent used to temporarily collect extension-type upgrades during processing. Created in OnCreate and disposed in OnDestroy.

  • private NativeList<Entity> subBuildings { get; set; }
    NativeList allocated with Allocator.Persistent used to temporarily collect sub-building upgrades during processing. Created in OnCreate and disposed in OnDestroy.

Properties

  • protected override string group { get; }
    Returns the UI group name for this section. For this class it returns "UpgradesSection". Used when binding UI triggers and writing types/properties in the JSON writer.

  • private NativeList<Entity> extensions { get; set; }
    (See Fields) Property accessor for the NativeList that stores extension entities.

  • private NativeList<Entity> subBuildings { get; set; }
    (See Fields) Property accessor for the NativeList that stores sub-building entities.

Constructors

  • public UpgradesSection()
    Default constructor. Marked with [Preserve] in source to prevent stripping. Initialization of native lists happens in OnCreate rather than here.

Methods

  • protected override void OnCreate()
    Initializes systems and resources:
  • Acquires ToolSystem, ObjectToolSystem, UIInitializeSystem, PoliciesUISystem, AudioManager from the World.
  • Prepares an EntityQuery for ToolUXSoundSettingsData.
  • Allocates extensions and subBuildings NativeList with persistent allocator.
  • Registers trigger bindings for the UI actions "delete", "relocate", "focus", and "toggle" (mapped to OnDelete, OnRelocate, OnFocus, OnToggle).

  • protected override void OnDestroy()
    Cleans up allocated resources: disposes the extensions and subBuildings NativeLists and calls base.OnDestroy().

  • protected override void OnGameLoaded(Context serializationContext)
    Called after a game load; iterates over policies from UIInitializeSystem to locate and cache the "Out of Service" PolicyPrefab into m_BuildingOutOfServicePolicy for later toggling.

  • private void OnToggle(Entity entity)
    Toggles the building "Out of Service" policy for the provided entity (or its parent when appropriate). It:

  • Checks whether the target entity (or extension) is currently inactive/disabled.
  • Calls PoliciesUISystem.SetSelectedInfoPolicy with the toggled value (uses the cached m_BuildingOutOfServicePolicy).

  • private void OnRelocate(Entity entity)
    Starts moving (relocating) the specified upgrade entity by calling ObjectToolSystem.StartMoving(entity) and setting ToolSystem.activeTool to the ObjectToolSystem.

  • private void OnDelete(Entity entity)
    Deletes the specified upgrade entity if it exists:

  • Plays the bulldoze UI sound (via ToolUXSoundSettingsData singleton from m_SoundQuery).
  • Adds a Deleted component to the entity through the EndFrameBarrier command buffer (so the deletion occurs at end of frame).

  • private void OnFocus(Entity entity)
    Toggles focus on the provided entity. If the camera controller is already following the entity, it unfocuses (passes Entity.Null); otherwise it focuses the InfoUI on that entity.

  • protected override void Reset()
    Clears the extensions and subBuildings NativeLists in preparation for re-population each frame/process.

  • private bool Visible()
    Determines whether the upgrades section should be visible for the currently selected entity:

  • Finds the upgradable (handles Attached -> m_Parent) and reads its PrefabRef.
  • Reads the BuildingUpgradeElement buffer from the prefab and checks whether any upgrade prefab has UIObjectData (i.e., is intended to appear in the UI).
  • Returns true if at least one visible upgrade exists.

  • private Entity GetUpgradable(Entity entity)
    Returns the actual upgradable entity (if the passed entity is Attached to a parent, returns that parent; otherwise returns the entity itself). Useful for when UI is showing info for attached/extension entities.

  • protected override void OnUpdate()
    Sets base.visible based on the Visible() result. Run each update so the section hides/shows depending on current selection and availability of UI-relevant upgrades.

  • protected override void OnProcess()
    Populates the extensions and subBuildings lists by reading InstalledUpgrade buffer from the upgradable entity:

  • For each installed upgrade, checks whether the upgrade's prefab has UIObjectData (means it's visible in UI).
  • Classifies each visible installed upgrade as Extension (added to extensions) or otherwise (treated as sub-building, added to subBuildings).
  • Leaves the collected lists in the NativeLists for use by OnWriteProperties.

  • public override void OnWriteProperties(IJsonWriter writer)
    Writes the collected upgrade data into the provided JSON writer for the UI:

  • Writes an "extensions" array with entries for each extension entity:
    • Each entry contains type group + ".Upgrade", name (bound via m_NameSystem), entity id, disabled flag (based on ExtensionFlags.Disabled), and focused flag (camera follow state).
  • Writes a "subBuildings" array similarly, determining disabled via BuildingOption.Inactive checks on Building components and focused flag similarly.
  • Used by UI binding/serialization to present the lists and attributes to the UI layer.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_ToolSystem = base.World.GetExistingSystemManaged<ToolSystem>();
    m_ObjectToolSystem = base.World.GetExistingSystemManaged<ObjectToolSystem>();
    m_UIInitializeSystem = base.World.GetOrCreateSystemManaged<UIInitializeSystem>();
    m_PoliciesUISystem = base.World.GetOrCreateSystemManaged<PoliciesUISystem>();
    m_AudioManager = base.World.GetOrCreateSystemManaged<AudioManager>();
    m_SoundQuery = GetEntityQuery(ComponentType.ReadOnly<ToolUXSoundSettingsData>());

    extensions = new NativeList<Entity>(5, Allocator.Persistent);
    subBuildings = new NativeList<Entity>(10, Allocator.Persistent);

    AddBinding(new TriggerBinding<Entity>(group, "delete", OnDelete));
    AddBinding(new TriggerBinding<Entity>(group, "relocate", OnRelocate));
    AddBinding(new TriggerBinding<Entity>(group, "focus", OnFocus));
    AddBinding(new TriggerBinding<Entity>(group, "toggle", OnToggle));
}

Notes and tips for modders: - The NativeList allocations use Allocator.Persistent and must be disposed in OnDestroy to avoid leaks (this class does so). - Deletion is performed by adding a Deleted component via the EndFrameBarrier command buffer; ensure any systems that react to Deleted run appropriately. - The "Out of Service" toggle uses PoliciesUISystem and a cached PolicyPrefab — ensure the policy name matches ("Out of Service") as used here. - UI visibility relies on the presence of UIObjectData on upgrade prefabs — if your custom upgrade should appear in this section, provide UIObjectData on its prefab.