Game.Prefabs.SoilWaterPrefab
Assembly: Game (assembly containing game prefabs)
Namespace: Game.Prefabs
Type: class
Base: PrefabBase
Summary:
Prefab that exposes configuration parameters for the soil/soil-water simulation. The prefab's public fields (annotated with Tooltips) define how rain, terrain height, diffusion, overflow and unit conversions affect the soil moisture simulation. At initialization this prefab adds and writes a SoilWaterParameterData ECS component to the corresponding entity so simulation systems can read these parameters.
Fields
-
public float m_RainMultiplier = 16f
Amount of water a "full rain" event adds to the soil simulation. Higher values increase how much soil moisture is added per rain. -
public float m_HeightEffect = 0.1f
How much terrain height affects where the soil water flows. Larger values make height differences influence flow more strongly. -
public float m_MaxDiffusion = 0.05f
Maximum portion of soil wetness that can change per update. Higher values increase diffusion speed but can make the simulation unstable. -
public float m_WaterPerUnit = 0.1f
How much surface water corresponds to one full cell/unit of soil water. Used to convert between surface water depth and soil moisture units. -
public float m_MoistureUnderWater = 0.5f
Target soil moisture when land is considered underwater. -
public float m_MaximumWaterDepth = 10f
Water depth threshold that counts as "fully underwater" for determining soil moisture behavior. -
public float m_OverflowRate = 0.1f
Portion of extra moisture that is transformed into surface water per update (how quickly excess soil moisture becomes surface runoff).
Properties
- (none declared by this class)
This prefab does not declare any C# properties. It exposes parameters via public fields that are written into the ECS component SoilWaterParameterData.
Constructors
public SoilWaterPrefab()
Default constructor. Field default values are declared inline (see field list). No custom initialization is performed in the constructor.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the component types this prefab requires to the provided set. This implementation calls the base and then ensuresSoilWaterParameterData
is added as a Read/Write component so the ECS entity created for this prefab contains the parameter component. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Overrides base method. In this class it currently delegates to base and does not add additional archetype components. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Called after the prefab entity is created. Ensures the PrefabSystem exists in the world and writes aSoilWaterParameterData
component to the created entity using the prefab field values: - m_RainMultiplier
- m_HeightEffect
- m_MaxDiffusion
- m_WaterPerUnit
- m_MoistureUnderWater
- m_MaximumWaterDepth
- m_OverflowRate
This is the link between the MonoBehaviour prefab inspector values and the ECS data the simulation systems consume.
Usage Example
// Example: LateInitialize (taken from prefab behavior) — sets ECS component from inspector fields.
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
entityManager.World.GetOrCreateSystemManaged<PrefabSystem>();
entityManager.SetComponentData(entity, new SoilWaterParameterData
{
m_RainMultiplier = m_RainMultiplier,
m_HeightEffect = m_HeightEffect,
m_MaxDiffusion = m_MaxDiffusion,
m_WaterPerUnit = m_WaterPerUnit,
m_MoistureUnderWater = m_MoistureUnderWater,
m_MaximumWaterDepth = m_MaximumWaterDepth,
m_OverflowRate = m_OverflowRate
});
}
Additional notes: - Tweak the public fields in the prefab inspector to tune soil water behavior; changes will be applied by writing the corresponding ECS component. - Be cautious raising m_MaxDiffusion high — it can cause numerical instability in the diffusion step of the simulation. - m_WaterPerUnit and m_OverflowRate control interactions between soil moisture and surface water (how much soil moisture becomes visible surface water and vice versa).