Skip to content

Game.Prefabs.MaintenanceVehicle

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: public class

Base: ComponentBase

Summary:
Defines a prefab component used to configure maintenance vehicles (park, road, snow, vehicle cleaning). This prefab exposes editable fields for maintenance type, capacity and rate. At prefab/archetype creation it registers the required ECS components (MaintenanceVehicleData, UpdateFrameData and runtime vehicle-related components). On entity initialization it writes the initial MaintenanceVehicleData and an UpdateFrameData entry (frame skip value 7) into the entity. The archetype registration logic conditionally adds components based on the configured maintenance type and whether the archetype already contains movement-related components.


Fields

  • public MaintenanceType m_MaintenanceType = MaintenanceType.Park
    Defines which maintenance roles this vehicle performs. This is a bitmask (flags) allowing combinations (e.g., Road | Snow). Default is MaintenanceType.Park.

  • public int m_MaintenanceCapacity = 1000
    Total maintenance capacity (units the vehicle can carry/perform) used to determine how much work the vehicle can do before returning/refilling. Default 1000.

  • public int m_MaintenanceRate = 200
    Rate at which the vehicle performs maintenance (units per interval). Default 200.

Properties

  • This class does not expose any properties.

Constructors

  • public MaintenanceVehicle()
    Default parameterless constructor (Unity/serialization will construct instances; fields are exposed for inspector overrides).

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds components required at the prefab level:
  • Adds MaintenanceVehicleData (read/write)
  • Adds UpdateFrameData (read/write) This informs the prefab system that entities instantiated from this prefab must contain those components.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds components required on the ECS archetype depending on existing archetype components and configured maintenance type:

  • Always adds Game.Vehicles.MaintenanceVehicle (read/write).
  • If the archetype already contains Moving, it also adds PathInformation and ServiceDispatch (read/write) because moving vehicles require path data and dispatch info.
  • If the maintenance type includes Park, adds ParkMaintenanceVehicle (read/write).
  • If the maintenance type includes any of Road, Snow, or Vehicle, adds RoadMaintenanceVehicle (read/write). This method ensures the entity archetype has the correct set of components for runtime systems.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when an entity is created from the prefab. This writes initial component data into the entity:

  • Sets MaintenanceVehicleData constructed from m_MaintenanceType, m_MaintenanceCapacity, m_MaintenanceRate.
  • Sets UpdateFrameData with value 7 (used to stagger/skip updates across frames). This populates the runtime components the simulation systems will read.

Usage Example

// Example: create a custom prefab by changing defaults in code
public class CustomMaintenanceVehiclePrefab : MaintenanceVehicle
{
    public CustomMaintenanceVehiclePrefab()
    {
        // Make this vehicle handle road + snow, with higher capacity and speed
        m_MaintenanceType = MaintenanceType.Road | MaintenanceType.Snow;
        m_MaintenanceCapacity = 1500;
        m_MaintenanceRate = 300;
    }
}

Additional notes: - The prefab is intended to be used by the game's prefab/asset pipeline (typically configured in the editor/inspector), so fields are exposed for designers to tweak without code. - The bitmask checks ((m_MaintenanceType & MaintenanceType.Park) != MaintenanceType.None) and ((m_MaintenanceType & (MaintenanceType.Road | MaintenanceType.Snow | MaintenanceType.Vehicle)) != MaintenanceType.None) determine which specialized maintenance components are added to the archetype.