Game.Prefabs.CargoTransport
Assembly: Assembly-CSharp.dll (game assembly; may appear under the game's runtime assembly)
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Prefab component for cargo transport vehicles. Defines capacity, transported resource types, maintenance range and registers required ECS components for cargo transport entities. During initialization it converts editor-specified transported resources into the in-game Resource bitmask and writes a CargoTransportVehicleData component (including a maintenance range converted to internal units).
Fields
-
public int m_CargoCapacity
Maximum cargo capacity of the vehicle (default 10000). Used when creating the CargoTransportVehicleData for the entity. -
public int m_MaxResourceCount
Maximum distinct resource types the vehicle can carry (default 1). -
public float m_MaintenanceRange
Maintenance range value specified on the prefab (note: multiplied by 1000f during initialization when stored in the component data). -
public ResourceInEditor[] m_TransportedResources
Array of resources editable in the prefab inspector. Values are converted via EconomyUtils.GetResource into the runtime Resource bitmask.
Properties
- None declared on this class. (All state is exposed via public fields and written into ECS component data during Initialize.)
Constructors
public CargoTransport()
Default constructor (no special construction logic in source; Unity/Mono will call default ctor when required).
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the runtime component type(s) that represent this prefab's configuration to the prefab definition. This method adds:-
CargoTransportVehicleData (read/write) This ensures the vehicle-specific data component will be present on instantiated entities.
-
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Registers the full set of ECS components required by runtime vehicles built from this prefab. Adds the following read/write component types: - Game.Vehicles.CargoTransport
- Resources
- LoadingResources
- Odometer Additionally, if the archetype already contains Moving and either does not contain Controller or does contain LayoutElement, it adds:
- PathInformation
-
ServiceDispatch This conditional logic controls whether pathfinding/dispatch components are included for this prefab's archetype.
-
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is instantiated to initialize entity component data. Behavior: - Aggregates the resources listed in m_TransportedResources into a Resource bitmask using EconomyUtils.GetResource().
- Creates and sets a CargoTransportVehicleData component on the entity containing:
- aggregated Resource bitmask,
- m_CargoCapacity,
- m_MaxResourceCount,
- m_MaintenanceRange multiplied by 1000f (unit conversion). This writes the vehicle configuration into the ECS entity so systems can use it at runtime.
Usage Example
// Example showing how the prefab initializes its component data.
// (This is the actual Initialize override from the prefab.)
public override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity);
// Convert editor ResourceInEditor[] into runtime Resource flags
Resource resource = Resource.NoResource;
if (m_TransportedResources != null)
{
for (int i = 0; i < m_TransportedResources.Length; i++)
{
resource |= EconomyUtils.GetResource(m_TransportedResources[i]);
}
}
// Write the CargoTransportVehicleData to the entity.
// Note: maintenance range is converted to internal units by multiplying by 1000f.
entityManager.SetComponentData(entity,
new CargoTransportVehicleData(resource, m_CargoCapacity, m_MaxResourceCount, m_MaintenanceRange * 1000f));
}
Notes and tips: - The prefab is decorated with [ComponentMenu("Vehicles/", typeof(VehiclePrefab))], so it will appear under the Vehicles menu in the editor. - m_TransportedResources is expected to be configured in the prefab inspector; the code accumulates their runtime representation using bitwise OR, so Resource is a flags-style enum. - The GetArchetypeComponents conditional ensures pathfinding/dispatch components are only added when appropriate for the prefab's behavior (e.g., moving vehicles that require path info).