Game.Prefabs.WaterSource
Assembly: Game (Assembly-CSharp)
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
A prefab component that defines a water source for the simulation. Exposes editable fields for radius, amount and initial pollution which are converted to an ECS component (WaterSourceData) when the prefab is initialized/converted. The component ensures the corresponding ECS component type is included in both the prefab and the archetype and writes the configured values to the entity on Initialize.
Fields
-
public float m_Radius
Radius of effect for the water source. Default in code: 50f. Used to populate WaterSourceData.m_Radius. -
public float m_Amount
The amount/strength of the water source. Default in code: 1f. Used to populate WaterSourceData.m_Amount. -
public float m_Polluted
Initial pollution level for the water source. Used to populate WaterSourceData.m_InitialPolluted.
Properties
- None. This component exposes only public fields; there are no C# properties declared.
Constructors
public WaterSource()
No explicit constructor is declared in the source; the default parameterless constructor is used. Field defaults are m_Radius = 50f, m_Amount = 1f, m_Polluted = 0 (unless modified in the inspector).
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the runtime/component conversion type for the water source to the prefab's component list: components.Add(ComponentType.ReadWrite()). Ensures that when the prefab is converted, the WaterSourceData component will be present on the resulting entity. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds the archetype component for the simulation namespace type: components.Add(ComponentType.ReadWrite()). This registers the ECS component type with the archetype so entities get the correct layout at creation. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called during prefab/entity initialization. Writes a WaterSourceData instance to the provided entity using the component field values: entityManager.SetComponentData(entity, new WaterSourceData { m_Radius = m_Radius, m_Amount = m_Amount, m_InitialPolluted = m_Polluted });
This transfers the authoring data from the MonoBehaviour/prefab into the ECS world.
Notes: - The code uses both WaterSourceData (unqualified) and Game.Simulation.WaterSourceData (fully qualified) — they refer to the simulation ECS component type used to store the runtime data. - The values should be set in the prefab inspektor (or by other authoring scripts) prior to conversion/initialization.
Usage Example
// Typical initialization happens automatically during prefab conversion.
// The component implementation writes its authoring fields to the ECS component:
public override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity);
entityManager.SetComponentData(entity, new WaterSourceData
{
m_Radius = m_Radius,
m_Amount = m_Amount,
m_InitialPolluted = m_Polluted
});
}
// In the Unity Editor you would configure m_Radius, m_Amount and m_Polluted
// on the WaterSource component attached to a prefab. During conversion that
// prefab's entity will receive a WaterSourceData component with those values.