Game.Prefabs.Modes.TransportStationMode
Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Modes
Type: class
Base: LocalModePrefab
Summary:
TransportStationMode is a prefab component used to apply mode-specific data (currently a comfort multiplier) to transport station prefabs. It holds an array of ModeData entries (each referencing a PrefabBase and a comfort factor) and provides lifecycle overrides to record changes, apply the configured mode data to ECS entities, and restore defaults from the original prefab components. The class looks up the legacy TransportStation component on the referenced prefab, maps that to an ECS Entity via PrefabSystem, and reads/writes the TransportStationData component via an EntityManager. It logs a critical message if a referenced target prefab does not contain the expected TransportStation component.
Fields
-
public ModeData[] m_ModeDatas
Array of ModeData entries. Each entry references a PrefabBase and the comfort multiplier to apply for that mode. The component iterates this array in its methods to update the corresponding ECS TransportStationData components. -
Nested class:
public class ModeData
public PrefabBase m_Prefab
Reference to the prefab that contains a TransportStation component. Used to find the corresponding TransportStationData ECS entity via PrefabSystem.public float m_ComfortFactor
Comfort multiplier value to be written into the TransportStationData.m_ComfortFactor field for the referenced prefab's entity.
Properties
- None. This class exposes no public properties; it uses public fields and overrides methods from LocalModePrefab.
Constructors
public TransportStationMode()
Default parameterless constructor. Typical usage is that the component is created and configured in the Unity editor (inspector) rather than constructed manually in code.
Methods
public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates m_ModeDatas and for each entry:- Gets the TransportStation component from the referenced PrefabBase.
- If missing, logs a critical error via ComponentBase.baseLog.Critical and continues.
- Resolves the associated ECS Entity using prefabSystem.GetEntity(component.prefab).
-
Calls entityManager.GetComponentData
(entity) — this read typically ensures the component exists (and may register the change or touch the component in the prefab pipeline). The method does not modify component data. -
public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates m_ModeDatas and for each entry: - Gets the TransportStation component from the referenced PrefabBase.
- If missing, logs a critical error and continues.
- Resolves the ECS Entity and reads its TransportStationData, sets TransportStationData.m_ComfortFactor to the ModeData.m_ComfortFactor, and writes the modified data back with entityManager.SetComponentData(entity, componentData).
-
This applies the configured comfort value to the runtime ECS component for that prefab.
-
public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates m_ModeDatas and for each entry: - Gets the TransportStation component from the referenced PrefabBase.
- If missing, logs a critical error and continues.
- Resolves the ECS Entity, reads the TransportStationData, and sets TransportStationData.m_ComfortFactor back to the value defined on the legacy TransportStation component (component.m_ComfortFactor). The value is then written back to the ECS component. Use this to revert any applied mode changes to the prefab's original default.
Usage Example
// Example: configure a TransportStationMode component in code (usually done in the editor)
var transportMode = gameObject.AddComponent<Game.Prefabs.Modes.TransportStationMode>();
transportMode.m_ModeDatas = new Game.Prefabs.Modes.TransportStationMode.ModeData[]
{
new Game.Prefabs.Modes.TransportStationMode.ModeData
{
m_Prefab = somePrefabBaseReference,
m_ComfortFactor = 1.25f
}
};
// At runtime, the prefab pipeline or game systems will call:
// transportMode.RecordChanges(entityManager, prefabSystem);
// transportMode.ApplyModeData(entityManager, prefabSystem);
// and when needed:
// transportMode.RestoreDefaultData(entityManager, prefabSystem);
Additional notes: - The component expects the referenced PrefabBase to contain a legacy TransportStation component. If that component is absent, a critical log is emitted and the entry is skipped. - The class interacts directly with Unity.Entities (EntityManager) and a PrefabSystem to map legacy prefab components to ECS entities; ensure those systems are available when calling the methods. - Typical usage is within the prefab/modding pipeline where LocalModePrefab-derived components are processed to adjust entity component defaults for different modes.