Game.Prefabs.MaintenanceDepot
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ComponentBase, IServiceUpgrade
Summary:
MaintenanceDepot is a prefab component used by Cities: Skylines 2 to configure a maintenance depot building. It exposes editable fields for which maintenance types the depot provides (park, road, snow, vehicle), the number of vehicles it can hold, and a vehicle efficiency multiplier. At prefab/archetype creation time it registers the appropriate ECS component types (MaintenanceDepotData, UpdateFrameData and conditional components such as ParkMaintenance, RoadMaintenance, Efficiency, ServiceDispatch and OwnedVehicle). During initialization it writes a MaintenanceDepotData component and an UpdateFrameData with a default update interval into the created entity.
Fields
-
public MaintenanceType m_MaintenanceType = MaintenanceType.Park
This flags enum controls which maintenance functions the depot handles. Typical flags include Park, Road, Snow, Vehicle. The class uses bitwise checks to conditionally add ParkMaintenance or RoadMaintenance to the archetype. -
public int m_VehicleCapacity = 10
Maximum number of vehicles owned/managed by this depot. This value is written to the MaintenanceDepotData during Initialize. -
public float m_VehicleEfficiency = 1f
Efficiency multiplier for vehicles dispatched from this depot. Written to MaintenanceDepotData on Initialize.
Properties
- This class does not declare any C# properties. It exposes its configuration through public fields and through ECS component data written in Initialize.
Constructors
public MaintenanceDepot()
No explicit constructor is declared in the source; the component uses the default parameterless constructor and public field defaults (Park, 10, 1f).
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds components required on the prefab itself: at minimum it adds MaintenanceDepotData and UpdateFrameData. These indicate that instances of the prefab will carry the data and have an update frame interval. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Registers the set of ECS component types that should be part of the entity archetype for this building. Always adds Game.Buildings.MaintenanceDepot. Conditionally adds: ParkMaintenance
if m_MaintenanceType includes Park.RoadMaintenance
if m_MaintenanceType includes Road, Snow or Vehicle.- If the prefab does not have a ServiceUpgrade component:
- Adds
Efficiency
if the prefab has a CityServiceBuilding component. - Adds
ServiceDispatch
andOwnedVehicle
to enable dispatching and vehicle ownership for the service.
- Adds
This method determines what data/behavior an instantiated entity will have based on the depot configuration and other components present on the prefab.
-
public void GetUpgradeComponents(HashSet<ComponentType> components)
Used when the building gains an upgrade variant. Adds component types that should be present for upgraded versions: Game.Buildings.MaintenanceDepot, ServiceDispatch, OwnedVehicle. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called to initialize entity component data when an instance of the prefab is created. Writes a MaintenanceDepotData struct populated from the public fields: - m_MaintenanceType
- m_VehicleCapacity
- m_VehicleEfficiency Also sets an UpdateFrameData with a hardcoded interval of 10 (UpdateFrameData(10)) so the building's ECS update timing is established.
Usage Example
// Typical usage in editor or prefab setup:
var depot = gameObject.AddComponent<Game.Prefabs.MaintenanceDepot>();
depot.m_MaintenanceType = MaintenanceType.Road | MaintenanceType.Snow;
depot.m_VehicleCapacity = 20;
depot.m_VehicleEfficiency = 1.15f;
// When the prefab system creates an entity for the building the engine will call:
// depot.GetPrefabComponents(...) and depot.GetArchetypeComponents(...)
// and later:
// depot.Initialize(entityManager, entity);
// Example showing Initialize being used directly (for debugging or custom spawning):
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = em.CreateEntity();
depot.Initialize(em, e);
// Read back the written data
var data = em.GetComponentData<Game.Buildings.MaintenanceDepot>(e); // struct carrying runtime state
var depotData = em.GetComponentData<MaintenanceDepotData>(e); // contains m_MaintenanceType, m_VehicleCapacity, m_VehicleEfficiency
If you are creating or modifying prefabs, ensure GetArchetypeComponents registers the correct components for the services you want the depot to provide; if you need custom upgrade behavior, implement/attach a ServiceUpgrade component and supply appropriate upgrade components via GetUpgradeComponents.