Game.UI.InGame.VehicleUIUtils
Assembly: Game (approx.)
Namespace: Game.UI.InGame
Type: static class
Base: System.Object
Summary:
Utility helpers used by the in-game vehicle UI to inspect vehicle entities, determine vehicle counts/capacities for a building/company owner, resolve vehicle destinations, and map vehicle runtime state/components to localized UI state keys. It also contains a small nested wrapper (EntityWrapper) used for JSON writing of an Entity together with its bound name via a NameSystem.
Fields
- None (the class is a static helper and does not declare instance fields).
This type does declare a nested readonly struct EntityWrapper (see Properties / Constructors / Methods sections below).
Properties
public Unity.Entities.Entity entity { get; }
(EntityWrapper)
Read-only property on the nested EntityWrapper that holds the wrapped Unity.Entities.Entity.
Constructors
-
public EntityWrapper(Unity.Entities.Entity entity)
Creates a new EntityWrapper that holds the provided entity. -
(No public constructors for VehicleUIUtils — it's a static class.)
Methods
-
public void Write(IJsonWriter writer, NameSystem nameSystem)
(EntityWrapper.Write)
Writes a JSON representation of the wrapped entity and its bound name via the provided NameSystem. If the wrapped entity is Entity.Null the JSON writes null for entity and name; otherwise it writes the Entity value and binds its name through the NameSystem. -
public static int GetAvailableVehicles(Unity.Entities.Entity vehicleOwnerEntity, Unity.Entities.EntityManager entityManager)
Returns the calculated available vehicle capacity for a building/company (vehicle owner entity). The method: - Reads an Efficiency buffer (if present) to compute effective efficiency (clamped to 1.0).
- Reads the PrefabRef component on the owner entity and inspects upgrade/combined components (via UpgradeUtils.TryGetCombinedComponent or direct TryGetComponent) to determine the specific facility/company data type (garbage, deathcare, fire, hospital, maintenance, police, prison, transport depot, post facility, transport company, etc.).
- Sums the appropriate vehicle capacities from the facility/company data using BuildingUtils.GetVehicleCapacity(efficiency, capacity).
- Returns the total number of vehicle slots available for that owner entity.
-
Note: If no PrefabRef or compatible component is found, returns 0.
-
public static Unity.Entities.Entity GetDestination(Unity.Entities.EntityManager entityManager, Unity.Entities.Entity vehicleEntity)
Resolves and returns the logical destination entity for the given vehicle: - Reads the vehicle's Target component to start from component.m_Target.
- If that target has a Connected component, resolves to the connected entity.
- If the resolved entity is an OutsideConnection or another Vehicle, returns it as-is.
- If the target is a CompanyData and has a PropertyRenter, returns the property entity.
- If the target has an Owner component, resolves owner.owner.
- If the target is a Creature.Resident, resolves to the linked citizen entity.
- If the original Target was a Waypoint that is not connected, attempts to find the next waypoint in the vehicle's route (RouteWaypoint buffer) and returns the Connected entity for a reachable waypoint.
-
Returns Entity.Null if no destination could be resolved.
-
public static VehicleStateLocaleKey GetStateKey(Unity.Entities.Entity entity, Unity.Entities.EntityManager entityManager)
Generic dispatch method that inspects the entity for known vehicle components (PublicTransport, PersonalCar, PostVan, PoliceCar, MaintenanceVehicle, Ambulance, GarbageTruck, FireEngine, DeliveryTruck, Hearse, CargoTransport, Taxi) and forwards to the appropriate overload to map runtime state & components to a VehicleStateLocaleKey. If no known vehicle component is present, returns VehicleStateLocaleKey.Unknown. -
public static VehicleStateLocaleKey GetStateKey(Unity.Entities.Entity entity, Game.Vehicles.PublicTransport publicTransportVehicle, Unity.Entities.EntityManager entityManager)
Maps PublicTransport vehicle state flags and components to a VehicleStateLocaleKey: - InvolvedInAccident => InvolvedInAccident
- ParkedCar or ParkedTrain => Parked
- PublicTransportFlags.Returning => Returning
- PublicTransportFlags.Boarding => Boarding
- PublicTransportFlags.Evacuating => Evacuating
-
Otherwise => EnRoute
-
public static VehicleStateLocaleKey GetStateKey(Unity.Entities.Entity entity, Game.Vehicles.PersonalCar personalCar, Unity.Entities.EntityManager entityManager)
Maps PersonalCar flags to locale keys: - InvolvedInAccident, ParkedCar
- PersonalCarFlags.Boarding => Boarding
- PersonalCarFlags.Disembarking => Disembarking
- PersonalCarFlags.Transporting => Transporting
-
Otherwise => EnRoute
-
public static VehicleStateLocaleKey GetStateKey(Unity.Entities.Entity entity, Game.Vehicles.PostVan postVan, Unity.Entities.EntityManager entityManager)
Maps PostVan flags: - InvolvedInAccident, ParkedCar
- PostVanFlags.Delivering => Delivering
- PostVanFlags.Collecting => Collecting
- PostVanFlags.Returning => Returning
-
Otherwise => Unknown
-
public static VehicleStateLocaleKey GetStateKey(Unity.Entities.Entity entity, Game.Vehicles.PoliceCar policeCar, DynamicBuffer<ServiceDispatch> dispatches, Unity.Entities.EntityManager entityManager)
Maps PoliceCar state with dispatch info: - InvolvedInAccident, ParkedCar
- PoliceCarFlags.Returning => Returning
- If AccidentTarget + request count + a dispatch exists:
- If AtTarget and the dispatch request is a PoliceEmergencyRequest referencing an AccidentSite, returns AccidentSite or CrimeScene depending on AccidentSiteFlags.
- If a PoliceEmergencyRequest exists but not at target => Dispatched.
- Otherwise => Unknown
-
Otherwise => Patrolling
-
public static VehicleStateLocaleKey GetStateKey(Unity.Entities.Entity entity, Game.Vehicles.MaintenanceVehicle maintenanceVehicle, Unity.Entities.EntityManager entityManager)
Maps MaintenanceVehicle flags: - InvolvedInAccident, ParkedCar
- TransformTarget flag: if target is involved in an accident => AccidentSite else Dispatched
-
Return/working flags => Working or Returning
-
public static VehicleStateLocaleKey GetStateKey(Unity.Entities.Entity entity, Game.Vehicles.Ambulance ambulance, Unity.Entities.EntityManager entityManager)
Maps Ambulance flags: - InvolvedInAccident, ParkedCar
- AmbulanceFlags.Returning => Returning
-
AmbulanceFlags.Transporting => Transporting else Dispatched
-
public static VehicleStateLocaleKey GetStateKey(Unity.Entities.Entity entity, Game.Vehicles.GarbageTruck garbageTruck, Unity.Entities.EntityManager entityManager)
Maps GarbageTruck flags: - InvolvedInAccident, ParkedCar
-
GarbageTruckFlags.Returning => Returning else Collecting
-
public static VehicleStateLocaleKey GetStateKey(Unity.Entities.Entity entity, Game.Vehicles.FireEngine fireEngine, DynamicBuffer<ServiceDispatch> dispatches, Unity.Entities.EntityManager entityManager)
Maps FireEngine flags/dispatch: - InvolvedInAccident
- FireEngineFlags.Extinguishing => Extinguishing
- FireEngineFlags.Rescueing => Rescuing
- If requestCount > 0 and dispatches.Length > 0 => Dispatched
- If not ParkedCar => Returning
-
Else => Parked
-
public static VehicleStateLocaleKey GetStateKey(Unity.Entities.Entity entity, Game.Vehicles.DeliveryTruck truck, Unity.Entities.EntityManager entityManager)
Maps DeliveryTruck flags: - InvolvedInAccident, ParkedCar
- DeliveryTruckFlags.Returning => Returning
- DeliveryTruckFlags.Buying => Buying
- DeliveryTruckFlags.StorageTransfer => Importing/Exporting depending on Owner/Target being OutsideConnection
- DeliveryTruckFlags.Delivering => Delivering
-
Otherwise => Transporting
-
public static VehicleStateLocaleKey GetStateKey(Unity.Entities.Entity entity, Game.Vehicles.Hearse hearse, Unity.Entities.EntityManager entityManager)
Maps Hearse flags: - InvolvedInAccident, ParkedCar
- HearseFlags.Returning => Returning
-
HearseFlags.Transporting => Conveying else Gathering
-
public static VehicleStateLocaleKey GetStateKey(Unity.Entities.Entity entity, Game.Vehicles.CargoTransport cargoTransport, Unity.Entities.EntityManager entityManager)
Maps CargoTransport flags: - InvolvedInAccident, ParkedCar/ParkedTrain
- CargoTransportFlags.Returning => Returning
- CargoTransportFlags.Boarding => Loading
-
Otherwise => EnRoute
-
public static VehicleStateLocaleKey GetStateKey(Unity.Entities.Entity entity, Game.Vehicles.Taxi taxi, Unity.Entities.EntityManager entityManager)
Maps Taxi flags: - InvolvedInAccident, ParkedCar
- TaxiFlags.Returning => Returning
- TaxiFlags.Dispatched => Dispatched
- TaxiFlags.Boarding => Boarding
- TaxiFlags.Transporting => Transporting
-
Otherwise => EnRoute
-
public static VehicleLocaleKey GetPoliceVehicleLocaleKey(PolicePurpose purposeMask)
Returns a localized vehicle type key for police vehicles based on the purpose mask: - PolicePurpose.Intelligence => PoliceIntelligenceCar
- PolicePurpose.Patrol => PolicePatrolCar
- Otherwise => Vehicle (generic)
Notes / Implementation details:
- Many methods use EntityManager.TryGetComponent and TryGetBuffer; they are safe if components/buffers are absent.
- Several overloads require a DynamicBuffer
Usage Example
// Example: Get available vehicles for a depot/building and map a vehicle to a UI state key.
using Unity.Entities;
// vehicleOwnerEntity is an Entity representing a building / transport depot (from UI selection)
int available = VehicleUIUtils.GetAvailableVehicles(vehicleOwnerEntity, entityManager);
// vehicleEntity is a vehicle selected in the UI
VehicleStateLocaleKey key = VehicleUIUtils.GetStateKey(vehicleEntity, entityManager);
// Example using EntityWrapper to write JSON with the NameSystem
var wrapper = new VehicleUIUtils.EntityWrapper(vehicleEntity);
wrapper.Write(jsonWriter, nameSystem);
If you want, I can produce separate focused examples (e.g., resolving destination for a vehicle, or showing how to supply the ServiceDispatch buffer when calling police/fire overloads).