Game.UI.InGame.VehicleSection
Assembly:
Assembly-CSharp
Namespace:
Game.UI.InGame
Type:
abstract class
Base:
InfoSectionBase
Summary:
Abstract UI info-section base for vehicle-related UI panels. Encapsulates common state and helpers used by concrete vehicle sections: current vehicle state key (for localization), owner/next-stop entity wrappers, and whether the owner is an outside connection. Overrides selection accessors to resolve through Controller/PrefabRef components when the selected entity is a controller proxy, and implements JSON serialization of its key properties for the UI writer.
Fields
None
This class defines no private fields. State is stored in protected auto-properties and read from ECS components via the inherited EntityManager.
Properties
-
protected VehicleStateLocaleKey stateKey { get; set; }
Holds the vehicle state key used for localized display (enum VehicleStateLocaleKey). Default is VehicleStateLocaleKey.Unknown (set in Reset). Used to determine whether nextStop should be resolved. -
protected VehicleUIUtils.EntityWrapper owner { get; set; }
Wrapper around the owner entity of the vehicle (populated in OnProcess). The wrapper exposes helper serialization via EntityWrapper.Write(writer, m_NameSystem). -
protected bool fromOutside { get; set; }
True when the owner entity has the Game.Objects.OutsideConnection component (i.e., the vehicle belongs to an outside connection). -
protected VehicleUIUtils.EntityWrapper nextStop { get; set; }
Wrapper around the next stop/destination entity for the vehicle. Note: nextStop is only resolved in OnProcess when the stateKey is not one of Returning, Patrolling, Collecting or Working. -
protected override Entity selectedEntity { get; }
Overrides the base selectedEntity accessor. If the currently selected entity has a Controller component (i.e., is a controller proxy), this property returns the controller's m_Controller entity; otherwise it returns base.selectedEntity. Implementation uses base.EntityManager.TryGetComponent(...) to detect controller proxies. -
protected override Entity selectedPrefab { get; }
Overrides the base selectedPrefab accessor. If the selected entity is a Controller and the controller entity has a PrefabRef component, this property returns the referenced prefab entity (component.m_Prefab). Otherwise returns base.selectedPrefab.
Constructors
protected VehicleSection()
[Preserve] attribute is applied. The constructor is parameterless and protected (class is abstract). No special runtime initialization occurs here; Reset is used to initialize the protected properties.
Methods
protected override void Reset()
Resets the section to default values:- stateKey = VehicleStateLocaleKey.Unknown
- owner = new VehicleUIUtils.EntityWrapper(Entity.Null)
- fromOutside = false
-
nextStop = new VehicleUIUtils.EntityWrapper(Entity.Null) Typically called by the UI lifecycle to clear state before reuse.
-
protected override void OnProcess()
Populates the runtime state for the currently selected vehicle: - Reads the Owner component of selectedEntity (base.EntityManager.GetComponentData
(selectedEntity).m_Owner) and wraps it in owner. - Sets fromOutside by testing for the Game.Objects.OutsideConnection component on the owner entity (base.EntityManager.HasComponent
(entity)). -
If stateKey is not Returning, Patrolling, Collecting or Working, resolves nextStop using VehicleUIUtils.GetDestination(base.EntityManager, selectedEntity) and wraps the result. This method should be called as part of the UI update cycle to refresh displayed information.
-
public override void OnWriteProperties(IJsonWriter writer)
Serializes the section state to JSON for the UI: - Writes "stateKey" as the enum name string (Enum.GetName(typeof(VehicleStateLocaleKey), stateKey)).
- Writes "owner" by calling owner.Write(writer, m_NameSystem).
- Writes "fromOutside" boolean.
- Writes "nextStop" by calling nextStop.Write(writer, m_NameSystem). Relies on m_NameSystem (inherited) and EntityWrapper serialization helpers.
Usage Example
// Example: subclassing VehicleSection to add custom info processing
public class MyVehicleInfoSection : VehicleSection
{
[Preserve]
protected override void Reset()
{
base.Reset();
// ensure a specific default, if desired
stateKey = VehicleStateLocaleKey.Unknown;
}
protected override void OnProcess()
{
base.OnProcess();
// Example: adjust stateKey based on some custom logic or additional components
// (pseudo-code — replace with real checks relevant to your mod)
if (base.EntityManager.HasComponent<SomeCustomComponent>(selectedEntity))
{
stateKey = VehicleStateLocaleKey.Working;
// when stateKey is Working, nextStop will not be updated by base.OnProcess()
}
// owner and nextStop are available as wrappers; they can be serialized in OnWriteProperties
}
public override void OnWriteProperties(IJsonWriter writer)
{
base.OnWriteProperties(writer);
// add extra properties if needed
}
}
Notes and dependencies: - Uses Unity.Entities (ECS) types: Entity, ComponentData access patterns via base.EntityManager. - Relies on game-specific types: Controller, PrefabRef, Owner, Game.Objects.OutsideConnection, VehicleStateLocaleKey, VehicleUIUtils.EntityWrapper, VehicleUIUtils.GetDestination, m_NameSystem (inherited from InfoSectionBase). - The class is abstract and intended to be extended by concrete UI sections that display vehicle details in-game.