Game.UI.InGame.DeliveryVehicleSection
Assembly: Game
Namespace: Game.UI.InGame
Type: class
Base: VehicleSection
Summary:
DeliveryVehicleSection is a UI section used in the in-game vehicle panel to display information about delivery vehicles (delivery trucks and post trucks). It integrates with the ECS/Unity.Entities world to detect whether the currently selected entity is a delivery vehicle, reads the DeliveryTruck component (or an aggregated resource set from a vehicle layout buffer), computes the current vehicle state key, selects an appropriate locale key (DeliveryTruck vs PostTruck) based on the contained resource flags, and exposes those values when serializing the UI state. The class is compiler-generated and contains Preserve attributes on members that are required to be kept by the runtime/linker.
Fields
- This class has no explicit fields declared in the source. It uses auto-properties and overrides from the base class.
Properties
-
protected override string group { get; }
Returns the UI group name for this section: "DeliveryVehicleSection". Used by the parent UI framework to categorize this section. -
private Resource resource { get; set; }
Tracks the Resource(s) associated with the current delivery vehicle(s). Resource is read from the DeliveryTruck component or aggregated from a layout buffer when the vehicle is a compound vehicle (reads multiple LayoutElement vehicle entries). The value is used to determine vehicle locale type and is serialized via OnWriteProperties. -
private VehicleLocaleKey vehicleKey { get; set; }
Locale key representing the kind of delivery vehicle for tooltips/labels (e.g., DeliveryTruck or PostTruck). Determined in OnProcess based on resource flags.
Constructors
public DeliveryVehicleSection()
Default constructor. Marked with [Preserve] on the class and some methods to avoid stripping. There is no special construction logic in this constructor.
Methods
-
protected override void Reset()
Overrides VehicleSection.Reset. Calls base.Reset() and resets the local resource property to Resource.NoResource. Ensures the section starts with a known state when reused. -
private bool Visible()
Returns a boolean indicating whether the UI section should be visible for the currently selected entity. The method returns true only if the selected entity has Vehicle, DeliveryTruck, and Owner components. Otherwise returns false. -
[Preserve] protected override void OnUpdate()
Called every update tick by the UI framework. This override sets base.visible according to the Visible() check so the section appears/disappears when an appropriate delivery vehicle is selected. -
protected override void OnProcess()
Core processing logic. Steps performed: - Reads the DeliveryTruck component for the selected entity.
- Attempts to read a readonly DynamicBuffer
for the selected entity. If present and non-empty, it iterates the buffer and, for each LayoutElement vehicle entry, tries to read its DeliveryTruck component and ORs together resource flags from those components. This aggregates resources carried by compound vehicles (e.g., articulated vehicles made of multiple sub-vehicles). - If there is no buffer, uses the single componentData.m_Resource value.
- Sets base.stateKey using VehicleUIUtils.GetStateKey(selectedEntity, componentData, base.EntityManager).
- Determines vehicleKey by checking if any of a specific mask ((Resource)28672uL) is present in resource: if so, vehicleKey = VehicleLocaleKey.PostTruck else VehicleLocaleKey.DeliveryTruck. (In other words, certain resource flags designate the vehicle as a postal vehicle.)
- Adds vehicleKey.ToString() to base.tooltipKeys so the UI shows the appropriate localized tooltip.
- Calls base.OnProcess() to let the parent class handle remaining logic.
Notes: - The mask 28672 (decimal) is used to detect certain resource types; the code performs a bitwise AND between resource and that mask and compares to Resource.NoResource. - Uses base.EntityManager APIs: HasComponent, GetComponentData, TryGetBuffer, TryGetComponent.
public override void OnWriteProperties(IJsonWriter writer)
Serializes a small part of the section state to JSON. It calls base.OnWriteProperties(writer) and then writes:- "resourceKey": Enum.GetName(typeof(Resource), resource)
- "vehicleKey": Enum.GetName(typeof(VehicleLocaleKey), vehicleKey) This makes the current resource and locale key available for remote debugging, UI state persistence, or tooling that consumes JSON from the UI.
Usage Example
// Example: the DeliveryVehicleSection is managed by the UI system and will automatically
// update visibility and contents when the selected entity changes. The following shows
// how the section ensures it only appears for delivery vehicles and writes out state.
[Preserve]
protected override void OnUpdate()
{
// This class sets its visibility based on the presence of Vehicle + DeliveryTruck + Owner
base.visible = Visible();
}
// Serialization example (called by UI system):
public override void OnWriteProperties(IJsonWriter writer)
{
base.OnWriteProperties(writer);
writer.PropertyName("resourceKey");
writer.Write(Enum.GetName(typeof(Resource), resource));
writer.PropertyName("vehicleKey");
writer.Write(Enum.GetName(typeof(VehicleLocaleKey), vehicleKey));
}
Additional notes: - The class depends on the Unity.Entities world (EntityManager) and game-specific components: Vehicle, DeliveryTruck, Owner, LayoutElement. - The class appends the vehicle locale key string to base.tooltipKeys; ensure the UI localization system has entries for the VehicleLocaleKey values (e.g., "DeliveryTruck", "PostTruck") if you need localized tooltips.