Game.Prefabs.Modes.SoilWaterMode
Assembly:
Assembly-CSharp.dll
Namespace:
Game.Prefabs.Modes
Type:
class
Base:
EntityQueryModePrefab
Summary:
SoilWaterMode is a mode-prefab component that exposes tunable parameters for the game's soil/water simulation. It provides editor-exposed floats (rain multiplier, height effect, diffusion, water-per-unit, underwater moisture, max water depth, overflow rate) and implements the glue to copy those values into the ECS world by targeting the SoilWaterParameterData singleton. It also supports restoring defaults from the associated SoilWaterPrefab via the PrefabSystem.
Fields
-
public System.Single m_RainMultiplier
Multiplier applied to rainfall/input water for the soil/water simulation. Tunable in the prefab inspector. -
public System.Single m_HeightEffect
Scalar that controls how terrain height affects water movement/retention. -
public System.Single m_MaxDiffusion
Maximum diffusion amount used when spreading water between cells/units. -
public System.Single m_WaterPerUnit
Amount of water represented by a single simulation unit. -
public System.Single m_MoistureUnderWater
Moisture level assigned when a cell is fully underwater (used by simulation logic). -
public System.Single m_MaximumWaterDepth
Cap for water depth used by the simulation to limit accumulation. -
public System.Single m_OverflowRate
Rate at which excess water overflows (used to move water off highly-saturated cells).
Properties
- (none declared)
This class exposes configuration via public fields; it does not declare C# properties.
Constructors
public SoilWaterMode()
Default (parameterless) constructor. No custom initialization is performed in the class source; instances are typically created/serialized by Unity as part of the prefab system.
Methods
-
public override EntityQueryDesc GetEntityQueryDesc()
Returns an EntityQueryDesc that matches entities containing the SoilWaterParameterData component. This is used by the mode/prefab system to locate the singleton parameter entity in the ECS world. -
protected override void RecordChanges(EntityManager entityManager, Entity entity)
Called to record changes for undo/synchronization. This implementation accesses the SoilWaterParameterData component on the provided entity (invoking GetComponentData), which typically marks the component as observed/recorded by the prefab system. -
public override JobHandle ApplyModeData(EntityManager entityManager, EntityQuery requestedQuery, JobHandle deps)
Applies the prefab's current field values into the ECS singleton. The method: - Fetches the singleton entity from requestedQuery.
- Reads SoilWaterParameterData from that entity.
- Copies all public field values (m_RainMultiplier, m_HeightEffect, m_MaxDiffusion, m_WaterPerUnit, m_MoistureUnderWater, m_MaximumWaterDepth, m_OverflowRate) into the component struct.
- Writes the updated component back via SetComponentData.
-
Returns the incoming JobHandle (no jobs are scheduled here).
-
public override void RestoreDefaultData(EntityManager entityManager, ref NativeArray<Entity> entities, PrefabSystem prefabSystem)
Restores parameter values from the prefab default (SoilWaterPrefab) into the ECS entity. Implementation: - Looks up the SoilWaterPrefab instance for the given entity via prefabSystem.GetPrefab
(entity). - Reads the current SoilWaterParameterData from the entity.
- Copies parameter defaults from the SoilWaterPrefab into the component struct.
- Writes the updated component back with SetComponentData. This is used when resetting modes to their default prefab values.
Usage Example
// Typical usage is via the Unity inspector on the prefab. Programmatically
// you can set fields and then apply them into ECS using ApplyModeData.
SoilWaterMode mode = /* obtained from a prefab or created in editor */;
mode.m_RainMultiplier = 1.2f;
mode.m_HeightEffect = 0.8f;
// ... set other fields as needed
// Later, when you have an EntityManager and a query that matches the SoilWaterParameterData singleton:
EntityQuery query = entityManager.CreateEntityQuery(ComponentType.ReadOnly<SoilWaterParameterData>());
// Apply mode values into the singleton component (synchronous, no jobs started)
mode.ApplyModeData(entityManager, query, default);
Notes and tips: - This class expects a singleton SoilWaterParameterData entity to exist; queries rely on that singleton pattern. - RestoreDefaultData depends on the PrefabSystem and a matching SoilWaterPrefab containing default values. - ApplyModeData performs immediate SetComponentData; if you integrate with jobs or write systems that run concurrently, ensure proper synchronization or scheduling of these updates.