Game.Prefabs.Modes.WaterPumpingStationMode
Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Modes
Type: class
Base: LocalModePrefab
Summary:
A LocalModePrefab that applies mode-specific adjustments to WaterPumpingStation entities. The component holds an array of ModeData entries, each of which targets a PrefabBase and describes how to modify the corresponding WaterPumpingStationData on the ECS entity (capacity multiplier and purification value). It supports recording (validation), applying mode changes, and restoring defaults. The nested ModeData class is marked [Serializable] so instances are set up in the inspector.
Fields
-
public ModeData[] m_ModeDatas
Array of ModeData entries. Each entry links to a PrefabBase (m_Prefab) and defines m_CapacityMultifier and m_Purification values to apply to the corresponding WaterPumpingStationData on the ECS entity. -
public class ModeData
(nested, [Serializable])
Contains the following fields: public PrefabBase m_Prefab
Reference to the prefab that contains a WaterPumpingStation component. Used to resolve the entity via PrefabSystem.public float m_CapacityMultifier
Multiplier applied to the existing WaterPumpingStationData.m_Capacity. Note: spelled "m_CapacityMultifier" in code.public float m_Purification
Purification value to set on WaterPumpingStationData.m_Purification.
Properties
- None declared on this class. (Behavior is provided via the override methods; any relevant ECS data is read/written through EntityManager and PrefabSystem.)
Constructors
public WaterPumpingStationMode()
Default parameterless constructor (implicitly provided). Instances are typically configured in the Unity inspector (m_ModeDatas).
Methods
-
public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates all ModeData entries, resolves the WaterPumpingStation component via the stored PrefabBase, logs a critical error (ComponentBase.baseLog.Critical) and continues if the component is missing. For valid entries it resolves the ECS Entity via prefabSystem.GetEntity(component.prefab) and calls entityManager.GetComponentData(entity). The recorded GetComponentData call validates/reads the component; the method does not modify the ECS component (it appears intended to ensure the component exists or to prime caches). -
public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
For each ModeData entry: - Resolves the WaterPumpingStation component from the referenced PrefabBase; logs and continues if missing.
- Gets the corresponding ECS entity via prefabSystem.GetEntity(component.prefab).
- Reads the WaterPumpingStationData from the EntityManager.
- Multiplies componentData.m_Capacity by modeData.m_CapacityMultifier (casts to int after multiplication).
- Sets componentData.m_Purification to modeData.m_Purification.
-
Writes the modified WaterPumpingStationData back to the entity with entityManager.SetComponentData. This is the method that applies the mode changes to in-game ECS data.
-
public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
For each ModeData entry: - Resolves the WaterPumpingStation component from the referenced PrefabBase; logs and continues if missing.
- Gets the associated ECS entity via prefabSystem.GetEntity(component.prefab).
- Reads WaterPumpingStationData and restores:
- componentData.m_Capacity = component.m_Capacity (value defined on the prefab component)
- componentData.m_Purification = component.m_Purification (value defined on the prefab component)
- Writes the restored WaterPumpingStationData back to the entity. Use this to reset mode changes back to the original prefab-defined defaults.
Notes and edge-cases: - The class expects that the referenced PrefabBase actually contains a WaterPumpingStation component. If not found, a critical log is emitted and the entry is skipped. - m_Capacity is converted to int after multiplication — be aware of rounding/truncation when using non-integer multipliers. - The RecordChanges method reads component data but doesn't store original values in the class fields; if you need to persist original values yourself, you must extend this class or store them elsewhere before ApplyModeData changes them.
Usage Example
// Example: programmatically applying mode data (typically Unity handles invocation)
public void ApplyModes(WaterPumpingStationMode mode, EntityManager em, PrefabSystem prefabSystem)
{
// This will validate entries and then apply adjustments defined in the inspector on m_ModeDatas
mode.RecordChanges(em, prefabSystem);
mode.ApplyModeData(em, prefabSystem);
}
// Example ModeData configuration in editor:
// m_ModeDatas[0].m_Prefab = <your water pumping prefab>
// m_ModeDatas[0].m_CapacityMultifier = 1.5f // increases capacity by 50%
// m_ModeDatas[0].m_Purification = 0.75f // sets purification to 75%