Game.Prefabs.WorkVehicle
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
WorkVehicle is a Component used on vehicle prefabs that represent "work" vehicles (e.g., service/utility vehicles). It exposes configurable data used at entity initialization: the vehicle's work type, an associated map feature, a list of resources it carries/uses in-editor, and a maximum work amount. The component declares the required prefab and archetype ECS components (WorkVehicleData, UpdateFrameData, Game.Vehicles.WorkVehicle, PathInformation) and populates WorkVehicleData on initialization. It also sets an UpdateFrameData(12) for car-type entities. The class is decorated with a ComponentMenu attribute and applies to CarPrefab, CarTrailerPrefab and WatercraftPrefab.
Fields
-
public VehicleWorkType m_WorkType
Controls the kind of work this vehicle performs (service/utility category). This value is copied into WorkVehicleData.m_WorkType on initialization. -
public MapFeature m_MapFeature = MapFeature.None
MapFeature associated with this vehicle. Copied to WorkVehicleData.m_MapFeature. -
public ResourceInEditor[] m_Resources
Array of in-editor resource descriptors. These are converted (via EconomyUtils.GetResource) into a combined Resource bitmask and written to WorkVehicleData.m_Resources. -
public float m_MaxWorkAmount = 30000f
Maximum amount of "work" the vehicle can hold/perform. Copied to WorkVehicleData.m_MaxWorkAmount.
Properties
- None (this component exposes public fields and uses ECS component data types; no C# properties declared).
Constructors
public WorkVehicle()
Default parameterless constructor (no custom initialization logic in the class).
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds prefab-level ECS component types required for this prefab:- ComponentType.ReadWrite
() -
ComponentType.ReadWrite
() -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds archetype-level ECS components required for entities created from this prefab: - ComponentType.ReadWrite
() -
ComponentType.ReadWrite
() -
public override void Initialize(EntityManager entityManager, Entity entity)
Initializes the ECS component data when the prefab entity is created: - Combines resources from m_Resources into a single Resource bitmask using EconomyUtils.GetResource and stores it in a WorkVehicleData instance.
- Sets WorkVehicleData fields: m_WorkType, m_MapFeature, m_MaxWorkAmount, m_Resources.
- Writes the WorkVehicleData to the entity via entityManager.SetComponentData.
- If the entity has a CarData component, sets UpdateFrameData to 12 via entityManager.SetComponentData(entity, new UpdateFrameData(12)).
Notes: - The resource combination uses bitwise OR to merge multiple Resource flags into a single Resource value. - The presence of the CarData component is used to detect car-like vehicles and adjust their update frequency/timing via UpdateFrameData.
Usage Example
// Example: reading the WorkVehicle data after entity creation
var workVehicleData = entityManager.GetComponentData<WorkVehicleData>(entity);
UnityEngine.Debug.Log($"Work type: {workVehicleData.m_WorkType}, Max work: {workVehicleData.m_MaxWorkAmount}");
// Example: configuring the prefab in code (normally done in inspector)
var prefab = new WorkVehicle();
prefab.m_WorkType = VehicleWorkType.GarbageCollection;
prefab.m_MapFeature = MapFeature.Road;
prefab.m_MaxWorkAmount = 40000f;
prefab.m_Resources = new ResourceInEditor[] { /* ... */ };
// When the prefab is instantiated, Initialize(...) will set the corresponding ECS component data.