Game.Prefabs.DeliveryTruck
Assembly:
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Prefab component that describes delivery-truck-specific data used when converting the prefab into an ECS entity. Carries configuration for cargo capacity, driving cost and the set of resources the truck can transport. When the prefab is instantiated into an entity, this class writes a DeliveryTruckData component to the entity and contributes archetype components required by runtime systems (including the runtime vehicle component and optionally PathInformation for car-based prefabs).
Fields
-
public int m_CargoCapacity = 10000
Maximum cargo capacity for this delivery truck, expressed in the same units the game uses for cargo (default 10000). This value is copied into DeliveryTruckData during Initialize. -
public int m_CostToDrive = 16
Cost-to-drive value for the truck (used by economy/AI logic). This value is copied into DeliveryTruckData during Initialize. -
public ResourceInEditor[] m_TransportedResources
Array of ResourceInEditor entries exposed on the prefab/editor that specify which resources this truck can carry. During Initialize these entries are converted into the runtime resource-bitmask using EconomyUtils.GetResource and OR'ed into DeliveryTruckData.m_TransportedResources. If null, no resources are added.
Properties
- (none defined on this class)
This prefab class does not declare C# properties. It exposes public fields that are serialized by the prefab/editor and used to populate the ECS DeliveryTruckData component.
Constructors
public DeliveryTruck()
Default parameterless constructor (inherited behavior). The class relies on field initializers for default values and the engine to call Initialize when producing entities from the prefab.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the component types that should be present on the prefab entity instance. Implementation adds ReadWriteso the DeliveryTruckData component will exist on entities created from this prefab. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds component types required by the entity archetype. Implementation always adds ReadWrite(). If the underlying base.prefab is a CarPrefab, it also adds ReadWrite () so car-prefabs get path-related data included in their archetype. -
public override void Initialize(EntityManager entityManager, Entity entity)
Populates and writes DeliveryTruckData to the given entity. It creates a DeliveryTruckData struct, fills m_CargoCapacity and m_CostToDrive from the prefab fields, converts any entries in m_TransportedResources to runtime resource flags via EconomyUtils.GetResource and accumulates them with bitwise OR, then calls entityManager.SetComponentData(entity, componentData).
Notes: - Transported resources are combined into a bitmask (flags) on DeliveryTruckData.m_TransportedResources. - There is a null-check on m_TransportedResources so absence of entries is handled gracefully.
Usage Example
// Example showing how the prefab fields get used during Initialize:
public class MyPrefabSetup : DeliveryTruck
{
// Fields are set in the inspector or via code before the prefab is instantiated.
}
// Engine/runtime will call something equivalent to:
EntityManager entityManager = ...;
Entity entity = ...; // created from archetype returned by GetArchetypeComponents
var prefab = new DeliveryTruck();
prefab.m_CargoCapacity = 8000;
prefab.m_CostToDrive = 20;
prefab.m_TransportedResources = new ResourceInEditor[] { /* entries chosen in editor */ };
prefab.Initialize(entityManager, entity);
// After this, the entity will have a DeliveryTruckData component populated
// with the configured cargo, cost and resource bitmask.
Additional remarks: - This prefab class depends on Game.Economy.EconomyUtils (for resource conversion), DeliveryTruckData (the ECS data component written), Game.Vehicles.DeliveryTruck (runtime vehicle tag/data), PathInformation (pathfinding data for CarPrefab), and the ComponentType utility for constructing archetypes. - The archetype includes PathInformation only for CarPrefab-derived prefabs; CarTrailerPrefab is available in the ComponentMenu but does not trigger PathInformation in this implementation.