Skip to content

Game.UI.InGame.VehicleWithLineSection

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

Type: abstract class

Base: VehicleSection

Summary:
VehicleWithLineSection is an abstract UI section used in the in-game vehicle inspector panels. It extends VehicleSection to add awareness of the vehicle's associated route/line (represented by a Unity.Entities.Entity). During processing it reads the CurrentRoute component (from Game.Routes) on the inspected entity and stores the route entity. It also participates in serialization by writing a "line" entry (the bound name via the name system) and a "lineEntity" entry (the Entity value) to an IJsonWriter. This class is intended to be subclassed by concrete UI sections that need to show or operate on a vehicle's line information.


Fields

  • protected Unity.Entities.Entity lineEntity { get; set; }
    Protected auto-property that holds the Entity representing the vehicle's current route/line. If no route is present, this will be Entity.Null. It is populated in OnProcess by reading the CurrentRoute component from the selected entity.

Properties

  • protected Unity.Entities.Entity lineEntity { get; set; }
    Same as the field entry above — an auto-property used by subclasses to determine whether the inspected vehicle is associated with a route and to access that route entity.

Constructors

  • protected VehicleWithLineSection()
    Default protected constructor marked with [Preserve]. Intended for use by the UI framework and for subclassing. No initialization logic beyond what the base constructor provides.

Methods

  • protected override void Reset()
    Resets section state when the UI section is recycled. This override clears lineEntity (sets it to Entity.Null) and calls base.Reset(). Ensures stale route references are not retained when the section is reused.

  • protected override void OnProcess()
    Called during the section processing cycle. This override attempts to get the CurrentRoute component from the currently selected entity via base.EntityManager.TryGetComponent(selectedEntity, out var component). If successful, it stores component.m_Route in lineEntity; otherwise sets lineEntity to Entity.Null. After updating lineEntity it calls base.OnProcess(). This is where the section picks up the vehicle's current route each frame/update.

  • public override void OnWriteProperties(IJsonWriter writer)
    Writes properties to the provided IJsonWriter for serialization/debugging. This implementation:

  • Calls base.OnWriteProperties(writer).
  • Writes a "line" property. If lineEntity is Entity.Null it writes JSON null; otherwise it calls m_NameSystem.BindName(writer, lineEntity) to write the name information for the route entity.
  • Writes a "lineEntity" property with the raw Entity value. Note: m_NameSystem is assumed to be available (from the base class or the UI environment) and is used to produce a readable name entry for the route.

Usage Example

using Unity.Entities;
using UnityEngine.Scripting;
using Colossal.UI.Binding;

[Preserve]
protected override void OnProcess()
{
    base.OnProcess();

    // lineEntity was set by VehicleWithLineSection.OnProcess().
    if (lineEntity != Entity.Null)
    {
        // Example: do something with the line entity, e.g. request its name via the name system
        // (m_NameSystem is defined in the base class; usage may vary depending on access)
        m_NameSystem.TryGetName(lineEntity, out var routeName);
        // Use routeName in your UI update logic...
    }
}

Notes and modding tips: - The class relies on the CurrentRoute component (Game.Routes.CurrentRoute) which stores the route Entity in m_Route. Ensure that the inspected entity actually has that component before relying on lineEntity. - Entity.Null is used to indicate "no route". Always check for Entity.Null before accessing route-related data. - When extending this class, call base.Reset(), base.OnProcess(), and base.OnWriteProperties(writer) where appropriate to preserve expected behavior. - The [Preserve] attribute on the constructor ensures the constructor isn't stripped by Unity code stripping in release builds; keep it on subclasses' constructors if they are created/reflected by the game.