Game.Prefabs.Modes.GroundWaterPoweredMode
Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Modes
Type: class
Base: LocalModePrefab
Summary:
GroundWaterPoweredMode is a mode prefab component used to adjust the runtime GroundWaterPowered behaviour for referenced prefabs when a mode is applied. It holds an array of ModeData entries which point to PrefabBase assets and provide multipliers for production and maximum groundwater. The class records required components, applies multiplicative adjustments to the ECS GroundWaterPoweredData, and can restore the original values from the MonoBehaviour component when the mode is removed. The class logs a critical error if a referenced target prefab does not contain a GroundWaterPowered component.
Fields
public GroundWaterPoweredMode.ModeData[] m_ModeDatas
Holds the list of mode entries. Each entry ties a PrefabBase to multipliers used to modify the corresponding GroundWaterPoweredData ECS component.
Nested class ModeData (public, serializable) — each element contains:
- public PrefabBase m_Prefab
Reference to the prefab that contains a GroundWaterPowered MonoBehaviour.
- public float m_ProductionMultiplier
Multiplier applied to the m_Production field of GroundWaterPoweredData.
- public float m_MaximumGroundWaterMultiplier
Multiplier applied to the m_MaximumGroundWater field of GroundWaterPoweredData.
Properties
- None (no public properties are declared in this class).
Constructors
public GroundWaterPoweredMode()
Default constructor (no custom initialization logic in source).
Methods
-
public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
Scans m_ModeDatas and for each referenced PrefabBase retrieves the GroundWaterPowered MonoBehaviour. If found, it resolves the corresponding Entity via prefabSystem.GetEntity(component.prefab) and calls entityManager.GetComponentData(entity) to ensure the component/data is present (this acts as a registration/record step). If the GroundWaterPowered component is missing on a referenced prefab, a critical log entry is emitted and processing continues. -
public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
For each ModeData entry: - Resolves the GroundWaterPowered MonoBehaviour from the referenced PrefabBase.
- Gets the ECS entity for that prefab and reads its GroundWaterPoweredData.
- Modifies componentData.m_MaximumGroundWater by multiplying with m_MaximumGroundWaterMultiplier and casting to int.
- Modifies componentData.m_Production by multiplying with m_ProductionMultiplier and casting to int.
- Writes the modified GroundWaterPoweredData back to the Entity via SetComponentData. If a referenced prefab lacks the GroundWaterPowered MonoBehaviour, a critical log entry is emitted and the entry is skipped.
Notes: multipliers are applied as float multiplications then cast to int (truncation toward zero). Ensure multipliers are set as intended (e.g., 1.0 = no change).
public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
For each ModeData entry:- Resolves the GroundWaterPowered MonoBehaviour from the referenced PrefabBase.
- Gets the ECS entity for that prefab and reads its GroundWaterPoweredData.
- Restores the ECS data fields from the values stored in the MonoBehaviour (component.m_MaximumGroundWater and component.m_Production).
- Writes the restored GroundWaterPoweredData back to the Entity. If the referenced prefab lacks the GroundWaterPowered MonoBehaviour, a critical log entry is emitted and the entry is skipped.
Important implementation notes: - The class depends on PrefabSystem.GetEntity to resolve the GameObject prefab to an ECS Entity and on GroundWaterPoweredData being present on that entity. - The code assumes the MonoBehaviour GroundWaterPowered contains authoritative default values for restore operations. - The code performs no bounds checks other than null-checking the component; ensure m_ModeDatas is not null and elements are valid PrefabBase references to avoid runtime errors.
Usage Example
// Programmatically create ModeData entries and apply the mode.
// Typically m_ModeDatas are set in the Unity inspector on the prefab, but you can set them in code as well.
var mode = new GroundWaterPoweredMode();
mode.m_ModeDatas = new GroundWaterPoweredMode.ModeData[]
{
new GroundWaterPoweredMode.ModeData
{
m_Prefab = somePrefabBase, // Prefab with GroundWaterPowered component
m_ProductionMultiplier = 1.2f, // Increase production by 20%
m_MaximumGroundWaterMultiplier = 0.8f // Reduce max groundwater to 80%
}
};
// When the game/mode system invokes mode application:
mode.ApplyModeData(entityManager, prefabSystem);
// Later, when restoring defaults:
mode.RestoreDefaultData(entityManager, prefabSystem);