Game.Prefabs.Modes.CargoTransportStationMode
Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs.Modes
Type: class
Base: LocalModePrefab
Summary:
Component used to apply mode-specific data to cargo transport station prefabs. It serializes an array of ModeData entries (each pairing a PrefabBase with a loading factor) and provides logic to record entity/component references, apply the configured loading factor to the runtime TransportStationData component, and restore the default loading factor from the original prefab. The class performs null checks and logs a critical message if the targeted CargoTransportStation component cannot be found on a given PrefabBase.
Fields
-
public ModeData[] m_ModeDatas
An array of ModeData entries. Each ModeData contains a PrefabBase reference and a float loading factor (m_LoadingFactor). This array is serialized and editable in the inspector. The class iterates this array in RecordChanges / ApplyModeData / RestoreDefaultData to locate the target prefab and update the corresponding ECS component data. -
public class ModeData
(nested, Serializable) public PrefabBase m_Prefab
Reference to the prefab containing a CargoTransportStation component. Used to resolve the prefab's Entity via PrefabSystem.public float m_LoadingFactor
The loading factor value to apply to the TransportStationData component on the runtime entity.
Properties
- (none)
Constructors
public CargoTransportStationMode()
Implicit default constructor (no custom initialization performed by this class).
Methods
public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates m_ModeDatas and for each entry:- Gets the CargoTransportStation component from the referenced PrefabBase.
- If missing, logs a critical message via ComponentBase.baseLog and continues.
- Resolves the prefab's runtime Entity using prefabSystem.GetEntity(component.prefab).
-
Calls entityManager.GetComponentData
(entity) to ensure the component type is known / recorded (the method does not modify data here; it's used to record component usage for prefab change tracking). -
public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates m_ModeDatas and for each entry: - Resolves the CargoTransportStation on the PrefabBase; logs and continues if missing.
- Resolves the runtime Entity for that prefab.
- Reads the TransportStationData component from the entity, sets its m_LoadingFactor to the ModeData.m_LoadingFactor value, and writes it back with entityManager.SetComponentData.
-
This method applies the configured mode value into the ECS component for use at runtime.
-
public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates m_ModeDatas and for each entry: - Resolves the CargoTransportStation on the PrefabBase; logs and continues if missing.
- Resolves the runtime Entity for that prefab.
- Reads TransportStationData from the entity, sets its m_LoadingFactor back to the prefab's original component value (component.m_LoadingFactor), and writes it back. Use this to revert any mode changes and restore defaults from the prefab.
Notes and implementation details: - The code expects the referenced PrefabBase to have a CargoTransportStation component. That component is expected to contain a reference/property named prefab used to fetch the runtime Entity via PrefabSystem. - The runtime component being modified is TransportStationData (struct) and specifically its m_LoadingFactor field. - Missing target components are logged with ComponentBase.baseLog.Critical($"Target not found {this}"). - Methods operate directly against Unity.Entities.EntityManager / PrefabSystem and assume the ECS component types are available.
Usage Example
// Example: configure a CargoTransportStationMode at runtime (typically done in editor)
// myPrefab is a PrefabBase reference (e.g. obtained via asset reference)
var modeComponent = gameObject.AddComponent<Game.Prefabs.Modes.CargoTransportStationMode>();
modeComponent.m_ModeDatas = new[]
{
new Game.Prefabs.Modes.CargoTransportStationMode.ModeData
{
m_Prefab = myPrefab,
m_LoadingFactor = 1.25f
}
};
// Note: ApplyModeData / RestoreDefaultData are called by the prefab/mode system
// with an EntityManager and PrefabSystem. You normally do not call them directly
// unless implementing or testing the prefab system integration.