Skip to content

Game.Prefabs.Modes.TransportDepotMode

Assembly:
Game (assembly inferred from file path; adjust if different)

Namespace:
Game.Prefabs.Modes

Type:
public class

Base:
LocalModePrefab

Summary:
TransportDepotMode is a prefab mode component used to apply per-prefab mode overrides for TransportDepot prefabs. It contains an array of ModeData entries that reference a Prefab and specify vehicle capacity and timing (production/maintenance) values. At runtime it records changes (so the prefab system tracks the underlying ECS component), applies the ModeData values to the TransportDepotData ECS component, and can restore the default values from the original TransportDepot component on the prefab.


Fields

  • public ModeData[] m_ModeDatas
    Array of ModeData entries. Each entry references a PrefabBase (the depot prefab) and the mode-specific values that should be written into the ECS TransportDepotData for that prefab.

Nested type ModeData fields: - public PrefabBase m_Prefab
Reference to the prefab that contains a TransportDepot component. Used to locate the corresponding entity via the PrefabSystem.

  • public int m_VehicleCapacity = 10
    Vehicle capacity override value for the depot when this mode is applied.

  • public float m_ProductionDuration
    Production duration override value.

  • public float m_MaintenanceDuration
    Maintenance duration override value.

Notes: The code expects each referenced PrefabBase to expose a TransportDepot component. If the component is not found, a critical log message is emitted and that entry is skipped.

Properties

  • (none declared)

Constructors

  • public TransportDepotMode()
    Default (compiler-generated) constructor. No custom initialization in source.

Methods

  • public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
    Iterates over m_ModeDatas and, for each referenced PrefabBase, finds its TransportDepot component and then resolves the entity via prefabSystem.GetEntity(component.prefab). Calls entityManager.GetComponentData(entity) to ensure the TransportDepotData component is read (this is typically used to mark the component as tracked/changed by the prefab system). If the TransportDepot component is missing on the referenced prefab, a critical log is emitted and that entry is skipped.

  • public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
    Applies the mode overrides to the TransportDepotData ECS component for each referenced prefab. For each ModeData:

  • Resolves the TransportDepot component from the referenced PrefabBase.
  • Gets the entity for that prefab via prefabSystem.
  • Reads TransportDepotData from the entity, sets m_VehicleCapacity, m_ProductionDuration and m_MaintenanceDuration to the ModeData values.
  • Writes the modified TransportDepotData back to the entity via entityManager.SetComponentData. If the TransportDepot component is missing the entry is skipped and a critical log is emitted.

  • public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
    Restores TransportDepotData on the entity to the original values defined on the TransportDepot component of the prefab. For each ModeData:

  • Resolves the TransportDepot component on the referenced PrefabBase to read the default values (component.m_VehicleCapacity, component.m_ProductionDuration, component.m_MaintenanceDuration).
  • Writes those defaults into the entity's TransportDepotData via entityManager.SetComponentData. Missing TransportDepot components are logged and skipped.

Behavioral notes: - All methods iterate over m_ModeDatas by index and skip entries where the expected TransportDepot component is not present. - The class depends on the existence of TransportDepot (MonoBehaviour/ComponentBase) and the ECS TransportDepotData component definitions to be present in the project. - PrefabSystem.GetEntity(component.prefab) must return a valid ECS Entity that has TransportDepotData for the calls to entityManager.Get/SetComponentData to succeed.

Usage Example

// Example: from some setup code where you have an instance of TransportDepotMode,
// an EntityManager and a PrefabSystem available.

var mode = new TransportDepotMode();

// Configure mode entries in the editor or at runtime:
mode.m_ModeDatas = new TransportDepotMode.ModeData[]
{
    new TransportDepotMode.ModeData
    {
        m_Prefab = someDepotPrefabBaseReference,
        m_VehicleCapacity = 20,
        m_ProductionDuration = 45f,
        m_MaintenanceDuration = 10f
    }
};

// When applying the mode (runtime):
mode.ApplyModeData(entityManager, prefabSystem);

// To restore defaults later:
mode.RestoreDefaultData(entityManager, prefabSystem);

Additional tips: - Ensure the PrefabBase references point to prefabs that have a TransportDepot component; otherwise the entries will be skipped and a critical log will be produced. - This component operates on the ECS TransportDepotData component. If that component layout changes, keep the mapping in ApplyModeData/RestoreDefaultData in sync. - Use RecordChanges before applying mode data when you need the prefab system to track component changes for saving/undo or network syncing.